I need a Function like that:
class Class_A
{
...
bool ShowVariableConstituents( CString ( * ValueOutput )( double ) );
...
}
bool Class_A::ShowVariableConstituents( CString ( * ValueOutput )( double ) )
{
double dUncalculatedValue;
....
if( ValueOutput )
{
CString strValue = ValueOutput( dUncalculatedValue );
}
....
}
Here is an example how i need to use it:
class Class_B : Class_A
{
...
int Calculate();
CString ValueOutput( double dValue );
...
}
CString Class_B::ValueOutput( double dValue )
{
CString strValue;
strValue.Format("%6.2f", ( dValue / m_dAmount * 100 ) );
return strValue;
}
int Class_B::Calculate()
{
...
ShowVariableConstituents( & Class_B::ValueOutput );
...
}
I get the Error:
Error 1 error C2664: ‘
Class_A::ShowVariableConstituents’:
conversion of Parameter 1 from
‘CString (__thiscall Class_B::*
)(double)’ in ‘CString (__cdecl
*)(double)’ not possible
Can you help me do it right?
regards
camelord
To make it possible to pass pointers to member functions you should modify your function as follows:
But it will not help since you want to pass the pointer to
Class_B::ValueOutputandClass_Adoesn’t know anything aboutClass_B.Your option is to make your function template:
Then you could use it as follows: