Results 1 to 4 of 4

Thread: Public inheritance... Private members?

  1. #1

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    Public inheritance... Private members?

    Assuming I have two classes, the base containing a private member variable and the other class being derived from base, what is stopping me from accessing that private variable as a member inside of the derived class?

    g++ gives me:

    'int base::variable' is private
    within this context
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  2. #2
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703

    Re: Public inheritance... Private members?

    What is stopping you? The rules of the language

    http://www.parashift.com/c++-faq-lit....html#faq-24.6
    an ending

  3. #3

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134

    Re: Public inheritance... Private members?

    OK... makes enough sense, I suppose that private members are really only for the implementation of the actual derived class, so that's where they should be put. Thanks a lot
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: Public inheritance... Private members?

    Use protected instead, that is why it is there.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width