CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 24

Threaded View

  1. #6
    Join Date
    Aug 2009
    Location
    Romania->Felnac
    Posts
    48

    Re: Constructor Inheritance

    Quote Originally Posted by Rajesh1978 View Post
    How we conclude that the constructors are not inherited??

    Because I can call the base class constructors like below which means that the the constructor is accissible .

    Code:
    class Base{
    public:
    Base(int x,int y){}
    };
    class Derived : public Base{
    
    public:
    Derived(int a,int b):Base(a,b) //I am calling the Base constructor
    {
    }
    };
    Thanks
    The commented line should be: i am passing constructor's arguments

    I'm sure that is called: "Passing constructor's arguments" (or something similar), that's not a actual function call of the constructor, if you need to explicit call the constructor you have a bigger problem with the design of class or class hierarchy.

    The constructor of base class is called even if you don't pass parameters (the default c-tor or with default parameters), so you can write: Derived(int a,int b){} // and do something in the c-tor body, of course you need default base c-tor for that.

    LE: That line actually says: When construct the "Base part" of Derived object run the Base constructor with the two parameters of the Derived constructor.
    Last edited by Zlatomir; May 4th, 2010 at 10:03 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured