Hi all,
I've found a few references that address this issue, however I haven't figured out what the solution is in the specific case that I'm dealing with. Hopefully someone can help me out. The following code prototypes the general idea that I'm working with:
class FooClass
{
public:
typedef void ( *pointerToDoubleTakingFunction ) ( double& );
FooClass(){};
~FooClass(){};
void setDoubleTakingFunction( pointerToDoubleTakingFunction
pDoubleTakingFunction )
{
pointerToDoubleTakingFunction_ = pDoubleTakingFunction;
};
protected:
pointerToDoubleTakingFunction pointerToDoubleTakingFunction_;
};
class BaseClass
{
public:
BaseClass(){};
virtual ~BaseClass(){};
virtual void computeFoo( double& fooValue ) =0;
}
class DerivedClass : public BaseClass
{
public:
DerivedClass(){};
~DerivedClass(){};
void setFooClassObject( FooClass* pointerToFooClassObject )
{
fooClassObject_ = fooClassObject;
};
void run()
{
fooClassObject_->setDoubleTakingFunction( &computeFoo );
};
void computeFoo( double& fooValue )
{
fooValue = fooValue * 2.0;
};
private:
FooClass fooClassObject_;
};
int main()
{
FooClass* pointerToFooClass = new instanceOfFooClass;
DerivedClass instanceOfDerivedClass;
instanceOfDerivedClass.setFooClassObject( pointerToFooClass );
instanceOfDerivedClass.run();
return 0;
};
I think this summarizes the gist of what I am attempting. Basically, I need to pass the non-static member function computeFoo() in DerivedClass to FooClass automatically, via the run() function in DerivedClass. Passing the address of computeFoo() doesn't work and I've tried following a few references on passing non-static member functions but nothing really works.
If anyone can help me sort this out, I would greatly appreciate it.
Thanks in advance!
Cheers,
Kartik