Search code examples
c++ros

What does bool(T::* ...) do?


From ROS 1's node_handle.h, a certain API is specified as:

template<class T, class MReq, class MRes>
ServiceServer NodeHandle::advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T* obj)

srv_func is a callback for this service, MReq is a request class, MRes is a result class. obj is because this is a class member version of the callback.

Can someone please explain what this syntax bool(T::*... means? Is it just enforcing that srv_func must be a class member of T, as opposed to any old function?


Solution

  • template<class T, class MReq, class MRes> ServiceServer NodeHandle::advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T* obj)
    

    This is a function template. T, MReq and MRes are template type parameters of the template.

    (const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T* obj)
    

    This is the parameter list of the function template

    bool(T::*srv_func)(MReq &, MRes &)
    

    This is the second parameter of the function template.

    The name of the parameter is srv_func and the type of the parameter is bool(T::*)(MReq &, MRes &). That type is pointer to non-static member function of class type T that returns bool and has parameters of type MReq &, MRes &.