Can a function be assigned or alter its definition, just like overriding a function by derived classes.
But at this time, it is out of scope from the class.
I mean like this:
//class.h
class MClass
{
public:
void function(); // this is the function I am referring to.
}
//class.cpp
void MClass::function() { }
//file1.cpp
MClass mclass;
void globalFunction() { }
mclass.function = globalFunction; //is this even possible?
Your
function()is a real function, you wantfunction Callbackinstead.see sample program: on ideone
You could set
func_ptrto any callabe objetOr bind to other object
You could also pass parameter to function by using std::bind and placeholders.