Jump to content
  • Advertisement
Sign in to follow this  
whaleyboy

Help on Inheritence needed!

This topic is 5044 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I'm trying to get my head around the whole inheritence thing and had a question... Say I have a base class (base_class) that has a private variable (x). Now, say I derive a new class from base_class called my_class (class my_class: public base_class) that adds a new private variable (y), and a public function that sets both x and y to a value. The compliler tells me I don't have access to x: "cannot access private member declared in class 'base_class'. I thought that as the child class was declared with the 'public' function it would be able to use it's own member functions to access the private varibles inherited from the base class...? Can anyone clear this up? Cheers!

Share this post


Link to post
Share on other sites
Advertisement
It also depends on the status of the variable in the base class. Public variables remain public in derived classes, protected variables become private and private variables are not accessable.

Alan

Share this post


Link to post
Share on other sites
Quote:
Original post by wild_pointer
Quote:
Original post by AlanKemp
protected variables become private
Alan


I don't think so.


I really dont know what I was thinking when I wrote that...

Protected is what the OP was after. Protected is like private, except that derived classes can also access them.

Alan

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!