Hi,
May I ask what is the correct syntax to achieve the following function pointer pattern?
I keep getting
error C2064: term does not evaluate to a function taking 0 arguments
Thank you.
class Apple
{
public:
Apple(int i)
{
if(i == 1)
{
juicer = &Apple::one;
}
else if(i == 2)
{
juicer = &Apple::two;
}
}
int (Apple::*juicer)();
int one()
{
return 1;
}
int two()
{
return 2;
}
int internaljuicer()
{
this->juicer();
}
};
class Basket
{
public:
Basket(Apple* a)
{
apple = a;
}
Apple* apple;
int getjuicer()
{
apple->juicer();
}
};
int main()
{
Apple apple(1);
Basket basket(&apple);
std::cout << basket.getjuicer() << std::endl;
return 0;
}