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

Discussion in 'C++' started by Siemel Naran, Jan 10, 2005.

  1. Siemel Naran

    Siemel Naran Guest

    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;
    };
     
    Siemel Naran, Jan 10, 2005
    #1
    1. Advertising

  2. Siemel Naran

    Ron Natalie Guest

    Re: Can Derived class static member access protected member frombase class?

    Siemel Naran wrote:
    > 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).
     
    Ron Natalie, Jan 10, 2005
    #2
    1. Advertising

  3. Siemel Naran

    Micah Cowan Guest

    Re: Can Derived class static member access protected member frombase class?

    Ron Natalie wrote:

    > Siemel Naran wrote:
    >
    >> Can Derived class static member access protected member from base class?
    >>

    >
    > 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... :)
     
    Micah Cowan, Jan 12, 2005
    #3
  4. "Micah Cowan" <> wrote...
    > 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.
     
    Victor Bazarov, Jan 12, 2005
    #4
  5. Siemel Naran

    Micah Cowan Guest

    Re: Can Derived class static member access protected member frombase class?

    Victor Bazarov wrote:
    > "Micah Cowan" <> wrote...
    >
    >>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.
    >


    Mm, never mind, I've spotted my thinko now.
     
    Micah Cowan, Jan 12, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Lomax
    Replies:
    5
    Views:
    471
    John Carson
    Jun 30, 2005
  2. Replies:
    1
    Views:
    397
    myork
    May 23, 2007
  3. Replies:
    1
    Views:
    389
    Victor Bazarov
    May 23, 2007
  4. Replies:
    4
    Views:
    511
    James Kanze
    Oct 23, 2007
  5. blangela
    Replies:
    8
    Views:
    668
    Erik Wikström
    Sep 26, 2008
Loading...

Share This Page