|
-
May 4th, 2010, 09:59 AM
#6
Re: Constructor Inheritance
 Originally Posted by Rajesh1978
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|