Jump to content
  • Advertisement
Sign in to follow this  
Mantear

Inheritance question

This topic is 4850 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

I've got a base class and a child class. The child class includes the base class as type public. In the base class, I've got a protected member variable, float Position[3]. In the child class, I want to re-declare that member variable as float Position[4]. In the base class, there are public functions to set the 3 positions. In the child class, I added another public function to set the 4th position. Now, when I use any of the 3 public base class functions to update Position for a child class object, it doesn't seem to be affecting the Position[4] member variable. Do I need to re-create the base class functions in the child class?

Share this post


Link to post
Share on other sites
Advertisement
Quote:

In the child class, I want to re-declare that member variable as float Position[4].


To my knowledge, this is not possible. What [I think!] it does is create two variables base::Position and child::Position.

You're likely better off explicitly doing something like:


struct base{
float a,b,c;
// stuff for a,b,c
// virtual stuff for all
};

struct child:
public base{
float d;
// stuff for d only.
// fix virtual stuff for all
};




Though I think that's not such a good idea in the first place. Depending on what this is being used for it might be best to always use the 4 element version, with element 4 assigned some identity.

And I am no expert, this all might be off a mistaken assumption.

Share this post


Link to post
Share on other sites
I wasn't sure if what I was doing was possible, but the compiler didn't throw any warnings or errors, so I figured I was safe. I'll re-declare the functions in my child class and see if they solves my issues.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!