protected member

M

m_schellens

With my compiler (g++ 3.4) and the following input
I get:
g++ test.cpp
test.cpp: In constructor `TrinaryExpr::TrinaryExpr()':
test.cpp:4: error: `ProgNode*ProgNode::down' is protected
test.cpp:17: error: within this context

Is this a compiler bug or what am I missing?
Thanks,
marc



class ProgNode
{
protected:
ProgNode* down;
ProgNode* right;

public:
ProgNode();
};

class TrinaryExpr: public ProgNode
{
public:
TrinaryExpr(): ProgNode()
{
down = new ProgNode();
down->down = 0;
}
};


int main( int argc, char* argv[])
{
return 0;
}
 
L

lilburne

With my compiler (g++ 3.4) and the following input
I get:



test.cpp: In constructor `TrinaryExpr::TrinaryExpr()':
test.cpp:4: error: `ProgNode*ProgNode::down' is protected
test.cpp:17: error: within this context

Is this a compiler bug or what am I missing?

Deriving from a base class only gives you the right to access the
protected members of the derived class in your objects of your own class.

Consider the following classes:

class A {
protected:
int a;
};

class B : public A {
};

class C : public A {
};

class C should not be able to access the 'a' with class B simply because
they both derive from the same base.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top