Visual studio is telling me I can't access a member variable from and instance of a parent class. Something like this:
class Parent {
protected:
int x;
};
class Child : public Parent {
public:
void foo(Parent* p) {
p->x;
}
};
I'm new to c++, is there something I'm doing wrong here?
Childas a friend ofParent. Just addfriend class Child;to the definition of classParent. This is okay if you are the maintainer ofParentand you know what all derived classes ofParentshould really do withx(it is a design issue). – Tobias Oct 11 '13 at 23:33