bool clsB::Caller(){
int iii;
using ptr_funB = bool(clsB::*)(int);
ptr_funB f = &funB_From_ClassB;
return (this->*f)(iii);
// return funA((iii));//How can I get the address of funB_From_ClassB??
};
ptr_funB f = &funB_From_ClassB;
return (this->*f)(iii);
};
int main()
{
clsB Bclass;
Bclass.Caller();
printf("over\n");
}
thanks , but I want to print out is "have to go there",
if I try to use something like using ptr_funA = bool(clsA::*)(int);
then compiler will told me type not match.
using ptr_funB = bool(clsB::*)(int);
//using ptr_funA = void(clsB::*)(int);
class clsA
{
public:
void funA( bool (clsB::*)(int i))
{
//for (int j=i;i<=0;i--)//Need i to do something
std::cout << "have to go there\n";
}
};
class clsB : public clsA
{
public:
int ii=3;
bool funB_From_ClassB (int);
void Caller();
};
int main()
{
clsB Bclass;
Bclass.Caller();
std::cout << "over \n";
}
Thanks solve many problem for me, thanks.
another question is : can class A get the code and parameter together?
C++ seem always ignore the parameter pass from class B.
Thanks for your responses and patience!
the function of class A like qsort(), and class B like compare function,
I want to pass a ptr to class A, many way can do it.
A have to loop the function from class B.
Now I solve it by some thing like EOF(end of file) at last binary codes struct, because class B do not
known when should stop. If anyone known the method, please help me, and last.. sorry about my
English.
I want to pass a ptr to class A, ... A have to loop the function from class B.
Since A is a base class of B one way to do this is to declare the function in common as virtual in the base class and call it's derived class implementation through a pointer to base instantiated on a derived object: http://stackoverflow.com/questions/9974868/c-call-derived-function-from-base-class-instance
You must the function as a pointer, otherwise it won't except it.
This kind of errors are spotted easily once you will develop more and more with c++ so don't worry about it.
If you're still having troubles doing that you can use a program such as checkmarx to detect vulnerabilities among your code and fix them.
Good luck!
Ben.