Hello, all!
The problem is:
I have two classes:
[tt]MyClass1 and MyClass2[/tt]
The header of [tt]MyClass2[/tt] is included into [tt]MyClass1[/tt], so that [tt]MyClass1[/tt] can create objects of type [tt]MyClass2[/tt].
Now I need to pass a pointer of a member function of [tt]MyClass1[/tt] to [tt]MyClass2[/tt] to let an instance of [tt]MyClass2[/tt] use a function of [tt]MyClass1[/tt].
I did it as follows:
It doesn't work. The compiler says:
[tt]
error C2440: '=' : cannot convert 'int (__thiscall MyClass1::*)(const class CString &)' in 'int (__cdecl *)(const class CString &)'
[/tt]
And if I change the variable type :
this pointer is not valid in MyClass2 context...
Any ideas ????????????????
The problem is:
I have two classes:
[tt]MyClass1 and MyClass2[/tt]
The header of [tt]MyClass2[/tt] is included into [tt]MyClass1[/tt], so that [tt]MyClass1[/tt] can create objects of type [tt]MyClass2[/tt].
Now I need to pass a pointer of a member function of [tt]MyClass1[/tt] to [tt]MyClass2[/tt] to let an instance of [tt]MyClass2[/tt] use a function of [tt]MyClass1[/tt].
I did it as follows:
Code:
...
//Somewhere in [tt]MyClass1[/tt]...
MyClass2 obj;
int (*func)(const CString& name);
func = GetTableHeight;
obj.SetExternFunc(func);
...
Code:
...
//In [tt]MyClass2[/tt].....
void MyClass2::SetExternFunc(int (*ext_func)(const CString&))
{
int abc = ext_func("test");
}
...
It doesn't work. The compiler says:
[tt]
error C2440: '=' : cannot convert 'int (__thiscall MyClass1::*)(const class CString &)' in 'int (__cdecl *)(const class CString &)'
[/tt]
And if I change the variable type :
Code:
...
//Somewhere in [tt]MyClass1[/tt]...
MyClass2 obj;
int ([COLOR=red yellow]MyClass1::[/color]*func)(const CString& name);
func = GetTableHeight;
obj.SetExternFunc(func);
...
Any ideas ????????????????