Reputation: 1208
I'm trying to store a pointer to a member function. The class that needs to store the pointer is declared as:
template <typename TDataType, typename T>
bool my_function(std::string topic_name,
void(T::*)(const TDataType&) fp,
T* obj)
I get the error:
error: expected ',' or '...' before 'fp'
void(T::*)(const TDataType&) fp,
Can someone tell me what's going on? Looks like it's a syntax error that I don't get.
Upvotes: 0
Views: 43
Reputation: 180594
The syntax for a member function pointer is
return_type(class_name::* function_pointer_name)(function_parameters)
So
template <typename TDataType, typename T>
bool my_function(std::string topic_name,
void(T::*)(const TDataType&) fp,
T* obj)
Needs to be
template <typename TDataType, typename T>
bool my_function(std::string topic_name,
void(T::* fp)(const TDataType&)'
T* obj)
Upvotes: 1
Reputation: 1930
Change:
void(T::*)(const TDataType&) fp
to
void(T::* fp)(const TDataType&)
Upvotes: 3