I have a class Athat has a pointer to an instance of a pure virtual class B. The class Cis inferred from Band will automatically have a pointer to A(which is its parent) and must gain access to its members. This can be achieved by adding friend class Cinside the class A, although then it is necessary for each class to be obtained from B.
Code example:
class A
{
public:
friend class B;
friend class C;
private:
void DoDomething();
};
class B
{
virtual void Tick() = 0;
protected:
A* m_pointerToA;
};
class C : public class B
{
virtual void Tick()
{
m_pointerToA->DoSomething();
}
};
Is there a way to force all derived classes from to Bhave access to the private and protected members of the class Athat they point to without having to add friend class Xfor each of them?