sinojelly / mockcpp

Two C/C++ testing tools, mockcpp and testngpp.
Apache License 2.0
67 stars 42 forks source link

how can i mock overloaded template functions #50

Open duxinyu-uestc opened 1 year ago

duxinyu-uestc commented 1 year ago

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 commented 1 year ago

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