I
Immortal Nephi
I need to pass function pointer by reference because it invokes first
function and then invokes second function with the same parameter.
How can I fix it?
class A
{
public:
A() : m_a( 5 ) {}
~A() {}
void Run( void (&rF)( const A &ra ) )
{
printf("Run\n");
rF( *this ); // OK
Go1( rF( *this ) ); // Error
}
void Go1( void (&rF)( const A &ra ) )
{
printf("Go1\n");
Go2( ? ); // Fix
}
void Go2( void (&rF)( const A &ra ) )
{
printf("Go2\n");
rF( *this ); // OK
}
};
void F1( const A &ra )
{
printf("Test: %d\n", ra.m_a );
}
int main()
{
A a;
a.Run( F1 );
return 0;
}
function and then invokes second function with the same parameter.
How can I fix it?
class A
{
public:
A() : m_a( 5 ) {}
~A() {}
void Run( void (&rF)( const A &ra ) )
{
printf("Run\n");
rF( *this ); // OK
Go1( rF( *this ) ); // Error
}
void Go1( void (&rF)( const A &ra ) )
{
printf("Go1\n");
Go2( ? ); // Fix
}
void Go2( void (&rF)( const A &ra ) )
{
printf("Go2\n");
rF( *this ); // OK
}
};
void F1( const A &ra )
{
printf("Test: %d\n", ra.m_a );
}
int main()
{
A a;
a.Run( F1 );
return 0;
}