I am facing problems with passing function pointer as arguments.
The declaration of pointer to function type :
typedef void(*cbk_fct)(void);
The class Operation
has a constructor that accept a cbk_fct
as argument the declaration is as follows:
class Operation
{
private:
cbk_fct m_fct_ptr;
public:
Operation(cbk_fct fct_ptr);
};
Operation::Operation(cbk_fct fct_ptr):
m_fct_ptr(fct_ptr)
{
}
Now the class User
will call the Constructor of Operation
class User
{
public:
User();
void userOperation();
};
void User::userOperation()
{
cout << "User operation"<<endl;
}
User::User()
{
Operation op(userOperation); // This version doesnt work
}
This call will give following error:
no matching function for call to 'Operation::Operation(<unresolved overloaded function type>)'|
no known conversion for argument 1 from '<unresolved overloaded function type>' to 'cbk_fct {aka void (*)()}'
However if I declared the function to be passed as parameter outside the class it will be accepted
void UserOperationNotInClass()
{
cout << "User operation"<<endl;
}
User::User()
{
Operation op(UserOperationNotInClass); // This version works
}
Clearly the error message mention that it is not able to convert from '' to 'cbk_fct, but from where comes this type 'unresolved overloaded function type'