I'm fairly nooby at C++ but have this question that I hope makes sense:
Can a method in class B call a method within class A under these conditions:
- B cannot inherit from A
- you cannot create an object of A within B
- the method in A cannot be static
For example, can this be done by passing an object of A by reference to the method call of B.
My next question would be, what if an object of B was created WITHIN an object of A. How does A reference itself to pass to the method of object B?
An example of what I'm imagining:
class A;
class B
{
int x = 10;
int y = 10;
public:
DoThis(A* obj);
};
B::DoThis(A* obj)
{
obj->DoThat(int x, int y);
}
class A
{
public:
DoSomething();
DoThat(int x, int y);
};
A::DoSomething()
{
B objB;
objB.DoThis(this);
}
A::DoThat(int x, int y)
{
std::cout << x << y;
}
int main()
{
A* objA = new A;
objA->DoSomething();
}