C
C. J. Clegg
Consider the following code...
class MyClass
{
public:
int Fct1( void );
int Fct2( void );
int Fct3( void );
void ExecFcts( void );
};
int MyClass::fct1( void )
{
// do some stuff
return 0
}
int MyClass::fct2( void )
{
// do some different stuff
return 0
}
int MyClass::fct3( void )
{
// do some still different stuff
return 0
}
void MyClass::ExecFcts( void )
{
struct
{
int anIntVar;
int (MyClass::*TheFct)( void );
} arrayOfFcts[ ] =
{
{ 0, &MyClass::Fct1 },
{ 1, &MyClass::Fct2 },
{ 2, &MyClass::Fct3 }
};
// This all compiles OK up to here.
// Then...
//
// try to call one of the functions in the struct array
arrayOfFcts[ 0 ].TheFct( );
// This makes a compile error
}
int main( int argc, char** argv )
{
MyClass theClass;
theClass.ExecFcts();
return 0;
}
I have read through the FAQ and every post I can find on dejanews on
this topic, in fact the FAQ educated me on the difference between a
pointer to a member function and a pointer to a non-member function
and the need to prepend "MyClass::" to the function names in the
struct array, and allowed me to get a clean compile up to the point
indicated in the code comment above.
But, I can't get the correct syntax for the function call.
I have tried every combination I can think of of:
arrayOfFcts[ 0 ].MyClass::TheFct( );
arrayOfFcts[ 0 ].*MyClass::TheFct( );
arrayOfFcts[ 0 ].MyClass::*TheFct( );
( ... with and without parens sprinkled liberally about...)
....and no luck.
I have done my research ... honest ... and I'm out of ideas.
class MyClass
{
public:
int Fct1( void );
int Fct2( void );
int Fct3( void );
void ExecFcts( void );
};
int MyClass::fct1( void )
{
// do some stuff
return 0
}
int MyClass::fct2( void )
{
// do some different stuff
return 0
}
int MyClass::fct3( void )
{
// do some still different stuff
return 0
}
void MyClass::ExecFcts( void )
{
struct
{
int anIntVar;
int (MyClass::*TheFct)( void );
} arrayOfFcts[ ] =
{
{ 0, &MyClass::Fct1 },
{ 1, &MyClass::Fct2 },
{ 2, &MyClass::Fct3 }
};
// This all compiles OK up to here.
// Then...
//
// try to call one of the functions in the struct array
arrayOfFcts[ 0 ].TheFct( );
// This makes a compile error
}
int main( int argc, char** argv )
{
MyClass theClass;
theClass.ExecFcts();
return 0;
}
I have read through the FAQ and every post I can find on dejanews on
this topic, in fact the FAQ educated me on the difference between a
pointer to a member function and a pointer to a non-member function
and the need to prepend "MyClass::" to the function names in the
struct array, and allowed me to get a clean compile up to the point
indicated in the code comment above.
But, I can't get the correct syntax for the function call.
I have tried every combination I can think of of:
arrayOfFcts[ 0 ].MyClass::TheFct( );
arrayOfFcts[ 0 ].*MyClass::TheFct( );
arrayOfFcts[ 0 ].MyClass::*TheFct( );
( ... with and without parens sprinkled liberally about...)
....and no luck.
I have done my research ... honest ... and I'm out of ideas.