In C++, how do i call a method member of class A from a class B, using a pointer? By the way Class A and B are of different types.
I read that when a pointer is pointing to member function it can only point member functions within the class. But how can i point to a member function outside the class?
for example:
class A
{
public:
int add(int x)
{
return x+x;
}
};
int main()
{
typedef int (A::*pointer)();
pointer func = &A::add;
A objt;
B objt2;
obt2.*func(2);// the compiler give me an error of incompatible with object type ‘B’
return 0;
}