mockcpp icon indicating copy to clipboard operation
mockcpp copied to clipboard

how can i mock overloaded template functions

Open duxinyu-uestc opened this issue 2 years ago • 1 comments

i try to mock overloaded template functions:

template <typename M>
  void publish(const boost::shared_ptr<M>& message) const
{
  //do
}

template <typename M>
  void publish(const M& message) const
{
  //do
}

my code is :

MOCKER((void(ros::Publisher::*)(const map_service::MapChanged &))&ros::Publisher::publish<const map_service::MapChanged &>)
.stubs();

i want to mock the second template function, but it doesn't work. Thanks for your help!

duxinyu-uestc avatar Jul 14 '23 11:07 duxinyu-uestc

error is:

error: no matches converting function 'publish' to type 'void (class ros::Publisher::*)(const MapChanged&) {aka void (class ros::Publisher::*)(const struct map_service::MapChanged_<std::allocator<void> >&)}'

and list several forms of overloaded template functions , Its meaning may be that it cannot match which specific function is required

duxinyu-uestc avatar Jul 17 '23 02:07 duxinyu-uestc