What are the rules for a subclass accessing protected member objects? I thought I understood them but my code disagrees.
I have a base class, defined as
class Datum {
public:
Datum(Datum *r, Datum *l) : right(r), left(l) {}
protected:
Datum *right, *left;
};
I subclass Datum as follows:
class Column: public Datum
{
public:
Column(Datum *r, Datum *l, string n, int s): Datum(r,l), name(n), size(s) {}
void cover() {
right->left = left;
left->right = right;
}
protected:
string name;
int size;
};
When I compile, using G++ v.4.5.1, I get the error messages pointing to the two lines in cover:
error: Datum* Datum::right is protected
error: within this context
error: Datum* Datum::left is protected
error: within this context
Obviously, making the section public causes the errors to go away. Why are they there when the section is protected?