Can Derived class static member access protected member from base class?

S

Siemel Naran

Can Derived class static member access protected member from base class?

class Base {
protected:
void setvariable(int);
};

class Derived : Base {
public:
static std::auto_ptr<Base> out(new Derived());
out->setvariable(3); // my compiler gives is not accessible error here!
return out;
};
 
R

Ron Natalie

Siemel said:
Can Derived class static member access protected member from base class?

No. Same reasons why it doesn't for a non-static member.
(I'm assuming that all that stuff after public: in Derived
is really in a member function).
 
M

Micah Cowan

Ron said:
No. Same reasons why it doesn't for a non-static member.

Um, isn't the very definition of a protected member that it can
be accessed by classes derived from the base?

I'm thinking the code may well be as seen in OP... :)
 
V

Victor Bazarov

Micah Cowan said:
Um, isn't the very definition of a protected member that it can be
accessed by classes derived from the base?

It's a bit more complicated than that. The issue of protected
access and how it sometimes "doesn't work" has been discussed so
many times here and in c.l.c++.moderated that it doesn't really
make sense to begin again.
 
M

Micah Cowan

Victor said:
It's a bit more complicated than that. The issue of protected
access and how it sometimes "doesn't work" has been discussed so
many times here and in c.l.c++.moderated that it doesn't really
make sense to begin again.

Mm, never mind, I've spotted my thinko now.
 

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
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top