There is an objects with field double (A :: *ptrToFunc)();
Object B
has got A
; Can't use it in objects B
.
class Foo
{
public:
double (Foo :: *ptrToFunc)();
private:
double func1();
double func2();
public:
Foo() : ptrToFunc{ &Foo::func1 } {}
}
class B
{
public:
Foo obj();
double countVal()
{
return (obj.*ptrToFunc)(); // use of undeclared identifier ptrToFunc
return (obj.ptrToFunc)(); // called object (..) not a function or function pointer
}
}
int main()
{
B obj_B;
double var = obj_B.countVal();
return 0;
}
I have read C++ Tutorial: Pointer-to-Member Function but it doesn't help me.