Hi,
i have a c++ class,
class XYZ
{
public:
void Function1 ( MyStruct * myStruct );
// member variables, etc
}
Note that, Function1 is non-static function. MyStruct is some typdef struct
now consider the following typdef.
typedef void MyFunction ( MyStruct * myStruct );
i have another function, (not part of any class). It takes a function pointer as its argument.
void Function2 ( MyFunction * pFn )
{
// body
}
Then, i go about creating an object of class XYZ, and pass the address of Function1 to it,
XYZ *object1 = new XYZ;
Function2 ( object1->Function1 );
This throws an error, cannot convert parameter 1 from 'void ( MyStruct *)' to 'MyFunction (__cdecl *)'
however, when i declareFunction 1 as static void Function1 ( MyStruct * ), the compiler compiles without any error.
Why is it that only a static member function is passed off without error and the non-static shows error?
I have tried type casting too,
Function2 ( (MyFunction*) object1->Function1 ); no avail.
I have also tried creating an object without the new operator, even then, no avail.
please help
i have a c++ class,
class XYZ
{
public:
void Function1 ( MyStruct * myStruct );
// member variables, etc
}
Note that, Function1 is non-static function. MyStruct is some typdef struct
now consider the following typdef.
typedef void MyFunction ( MyStruct * myStruct );
i have another function, (not part of any class). It takes a function pointer as its argument.
void Function2 ( MyFunction * pFn )
{
// body
}
Then, i go about creating an object of class XYZ, and pass the address of Function1 to it,
XYZ *object1 = new XYZ;
Function2 ( object1->Function1 );
This throws an error, cannot convert parameter 1 from 'void ( MyStruct *)' to 'MyFunction (__cdecl *)'
however, when i declareFunction 1 as static void Function1 ( MyStruct * ), the compiler compiles without any error.
Why is it that only a static member function is passed off without error and the non-static shows error?
I have tried type casting too,
Function2 ( (MyFunction*) object1->Function1 ); no avail.
I have also tried creating an object without the new operator, even then, no avail.
please help
Comment