It is not recommended to use a variable of class public. If you want to access afrom Child, you should have something like this:
class Base {
public:
Base(): a(0) {}
virtual ~Base() {}
protected:
int a;
};
class Child: public Base {
public:
Child(): Base(), b(0) {}
void foo();
private:
int b;
};
void Child::foo() {
b = Base::a;
}
I would not directly contact a. It would be better if you use the method publicor protectedgetter for a.
source
share