class A
{
protected:
int m_a;
int m_b;
};
class B: public A
{
};
In class B i want to make m_a
private.
Does the following the correct way to do it
class B:public A
{
private:
int m_a;
};
Won't this result in 2 copies of m_a
?
The correct way to adjust the access control of a member is with a using
declaration:
class B: public A {
private:
using A::m_a;
}
Just writing int m_a;
would indeed result in two copies of m_a
, and a derived class would be able to access A
's copy of m_a
by writing A::m_a
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With