i'm using pointer to function inside my class to handle event.
For example:
Code:
#include <iostream>
using namespace std;
// MY_CLASS
class test
{
private:
string value;
public:
void SetValue(string source)
{ if (OnValueChange!=NULL)(*OnValueChange)(value,source);
value = source;}
string GetValue() { return value;}
void (*OnValueChange)(string OldValue,string NewValue);
};
// END_MY_CLASS
//MAIN PROGRAM
void handleOnValueChange(string OldValue,string NewValue)
{
cout<<"OLD VALUE : " << OldValue << "\n";
cout<<"NEW VALUE : " << NewValue << "\n";
cout<<"-----------------------------\n";
}
int main(int argc, char *argv[])
{
test *atest ;
atest = new test;
atest->OnValueChange = handleOnValueChange;
atest->SetValue("TEST");
atest->SetValue("ANOTHER TEST");
delete atest;
system("PAUSE");
return 0;
}
//END MAIN PROGRAM
This is a good idea or is better using virtual function,inheritance ??
thanx,
Gianni