I have an istance of a class A, that has some methods like:
class A
{
...
public:
bool DoOperation_one(Mytype* pSomeValue);
bool DoOperation_two(Mytype* pSomeValue);
...
bool DoOperation_th(Mytype* pSomeValue);
...
}
Another class, class B, has a pointer to A class and a method BMethod.
Class B
{
...
A* myPtrA;
...
bool BMethod(...); // arguments have to be defined
}
Is it possible to pass to BMethod, methods of A class instance as argument? I will try to be more clear with the follow pseudocode. In same place in class B i call BMethod with myPtrA method as argument (with parameters). I don't want to execute the myPtrA->DoOperation_two(somevalue) at calling time, but only in the BMethod (if statement):
...
bool bVal = BMethod(myPtrA->DoOperation_two(somevalue))
...
bool B::BMethod("valid signature" myFunction)
{
bool bfun=false;
if (myFunction)
{
do_something....
}
return bfun;
}
My goal is to call BMethod argument (DoOperation_one, DoOperation_two or DoOperation_th) in the body of BMethod only. I have been used template, but DoOperation_XXX is executed at calling time.
....
bool bVal = BMethod(myPtrA->DoOperation_two(somevalue));
or
bool bVal = BMethod(myPtrA->DoOperation_one(somevalue));
...
template <typename FunctionT>
bool BMethod(FunctionT myFunc)
{
bool bfun=false;
bool breturn = false;
while (!bfun)
{
if (myFunc)
{
bfun=true;
breturn = some_other_operation();
}
}
return breturn ;
}
Moreover, myFunc contains result of myPtrA->DoOperation_one(somevalue), and doesn't change in the while statement because it has executed at calling time.
Is there any other approach/solution?