Thread: Inheritance related question. Is this correct?

  1. #1
    Unregistered
    Guest

    Inheritance related question. Is this correct?

    People, tell me if this is correct. Im doing this in order to save some code in my constructors, but dont know if its a good practice, a bad one, or incorrect.

    Suppose I have two classes, a Control class and a derived Window class (class Window : public Control). They both may point to a Parent, and the pointer is set at construction time.

    Control::Control(Parent* parent)
    {
    m_ParentPtr = parent;

    // init stuff
    }

    Then in the Window constructor:

    Window::Window(Parent* parent)
    {
    // is this correct?
    Control::Control(parent);

    // init Window related stuff
    }

    Ok, hope you understand my question. Im also calling a lot the default constructor in some overloaded ones like:

    Class::Class()
    {
    // init basic stuff
    }

    Class:Class(int foo)
    {
    m_Foo = foo;
    Class::Class(); // call default constructor
    }

    Thx.

  2. #2
    Unregistered
    Guest
    found my answer in another forum. Try this URL.
    http://www.parashift.com/c++-faq-lit....html#faq-10.3

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scope Related question
    By csonx_p in forum C++ Programming
    Replies: 13
    Last Post: 08-24-2008, 11:02 AM
  2. A question related to BGI
    By progue in forum Windows Programming
    Replies: 6
    Last Post: 05-25-2008, 10:04 AM
  3. question related to keypad
    By lovemagix in forum C++ Programming
    Replies: 22
    Last Post: 01-05-2006, 02:25 AM
  4. A Little Performance Related SDL Question...
    By Comrade_Yeti in forum Game Programming
    Replies: 14
    Last Post: 12-09-2005, 07:46 PM
  5. n00b question.... dat file related
    By hobbes67 in forum C Programming
    Replies: 7
    Last Post: 06-24-2005, 11:39 AM