I want to define a base class A which allows different type of logging (file stream, console, etc). In the meantime, I want a class B to to be able to call A's print function (i.e. derived class C's print function which defines the logging method). However, I don't want to make A's print function to be public because it will only be called by B. Please could anyone suggest a better approach to re-design this? Many thanks!
class A
{
protected:
virtualvoid print(void);
};
class B
{
public:
B(A * a) : m_pA(a) {}
private:
void foo() { m_pA->print(); } // fail here
A * m_pA;
};
class C : public A
{
private:
virtualvoid print(void) { /*use different print*/ }
}