Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

c++ inheritance question

Started by tjrr3d Apr 21, 2006 at 8:28 PM 5 replies 750+ views
Original Post
tjrr3d
tjrr3d
Say I inherit a class but instead of overriding a function, I want to append on to it. Is there a way to call the parent function first from the child class? example:

class Parent
{
    public:
       Parent();
       ~Parent();

       Update();
};

Parent::Parent(){
}
Parent::~Parent(){
}
Parent::Update(){
  // Update X
}



class Child : public Parent
{
    public:
       Child();
       ~Child();

       Update();
};

Child::Child(){
}
Child::~Child(){
}
Child::Update(){
  // Call parent Update() to update X
  // Now update y
}

hplus0603
hplus0603
void Child::Func(){  Parent::Func();  std::cout << "More stuff" << std::endl;}

enum Bool { True, False, FileNotFound };
pcxmac
pcxmac
is it a rule of thumb that all inherited classes have their respective destructors virtualized? even if they are non-existant or empty?
sig
tjrr3d
tjrr3d
That last one will work great for what I need Anonymous Poster. Thanks guys.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.