So I have a base class with two derived classes (deriv1 and deriv2). On the deriv2 class I need to access a private member from deriv1... How can I do this?
Sample code:
class base
{
private:
public:
base() {};
~base() {};
};
class deriv1 : public base
{
private:
int m_member1;
public:
deriv1() {};
~deriv1() {};
};
class deriv2 : public base
{
private:
int m_member2;
public:
deriv2() {};
~deriv2() {};
int sum_members_because_yes(void)
{
return (deriv1::m_member1 + m_member2); // <---- :((
}
};
How can I access a private member from another derived class? I was trying to avoid using friend functions, or changing the private member to public... What do you advice?
Thank you! :)
deriv2has no reason to contain fields fromderiv1. What are you trying to model ? - Quentin