X
xuatla
Hi,
I have the following code for function pointer. compiling is ok. Can you
help me to check whether it's a good way to implement as:
class CA
{
.....
private:
void f1( double ) ;
void f2( double ) ;
private:
void (*CA::func)(double); // Q: is "CA::" here a must?
public:
void evalfunc( void (*f)(double) ) ; // Q: is this ok?
// I tried to use ( void (CA:*f)(double),
// but not good.
public:
void solve() ;
} ;
void CA::f1( double x ) { return 1.0; }
void CA::f2( double y ) { return 2.0; }
void CA::evalfunc( void (*f)(double) )
{
f(1); // ok.
.....
}
void CA::solve()
{
func = &CA::f1; // Q: if I dont use "CA::" or "&",
// then compile error.
// any other way for this part?
// above ok. but below not.
evalfun( func ); // error. Q: how to write this part?
// evalfunc( CA::func ); // error
}
Thanks a lot in advance for the help!
-xuatla
I have the following code for function pointer. compiling is ok. Can you
help me to check whether it's a good way to implement as:
class CA
{
.....
private:
void f1( double ) ;
void f2( double ) ;
private:
void (*CA::func)(double); // Q: is "CA::" here a must?
public:
void evalfunc( void (*f)(double) ) ; // Q: is this ok?
// I tried to use ( void (CA:*f)(double),
// but not good.
public:
void solve() ;
} ;
void CA::f1( double x ) { return 1.0; }
void CA::f2( double y ) { return 2.0; }
void CA::evalfunc( void (*f)(double) )
{
f(1); // ok.
.....
}
void CA::solve()
{
func = &CA::f1; // Q: if I dont use "CA::" or "&",
// then compile error.
// any other way for this part?
// above ok. but below not.
evalfun( func ); // error. Q: how to write this part?
// evalfunc( CA::func ); // error
}
Thanks a lot in advance for the help!
-xuatla