0
How can i call just parameterize constructor of base class?
I created a object of Derived class and now i just want to call default parameter of derive class but parameterize constructor of base class also..can anyone help me? #include<iostream> using namespace std; class base{ int a; public: base(){ cout<<"Base Default Constructor"<<endl; } base(int a){ cout<<"Base parameter Constructor"<<endl; } }; class derived: public base{ int a; public: derived(){ cout<<"Derive Default Constructor"<<endl; } derived(int a){ cout<<"Derive parameter Constructor"<<endl; } }; int main(){ derived d; }
7 Answers
+ 3
Zubair Ul Amin so I am telling you. When you create an object it's called default constructor of derived class..okay.
And then you call parameterized constructor of super class inside the default constructor of derived class...okay.
https://code.sololearn.com/c20qVtSML324/?ref=app
+ 2
Graphix Track Yes ,it's very simple .you created object of derived class it's automatically called default constructor of derived class and then you can call parameterized constructor of base class from default constructor of derived class.
+ 2
Zubair Ul Amin
YOU : I'm taking about multilevel inheritance
.
.
But, you used single inheritance..(one parent ,one child class)
0
Navya Sri but when i pass value through object it call parameterize constructor of Derived class
0
Aysha Simra I'm taking about multilevel inheritance