Constructor inheritence

This is a discussion on Constructor inheritence within the C++ Programming forums, part of the General Programming Boards category; My c++ is a bit rusty in the case of class related matters. I'm wondering how / if constructors are ...

  1. #1
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704

    Constructor inheritence

    My c++ is a bit rusty in the case of class related matters.

    I'm wondering how / if constructors are inherited in derived classes. Take for example this class:
    Code:
    class Agent() {
         Agent();
         Agent(vector Location);
         ~Agent();
    
        // other non important functions
    };
    
    class Worker : public Agent {
    
         // class functions
    
    };
    Now can the base class constructor be used as the constructor for the derived class? IE
    Worker *object = new Worker(position);

    Can any one offer the specifics of this application? Is it legal, better way to do it, etc etc.

    Thanks.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Worker in fact has a default constructor but the Agent constructor is called first. Yes, it is inherited.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    What about the case of me wanting to use the overloaded function? Agent(sVector location) for the worker class?
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21