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; }

3rd Dec 2020, 1:41 PM
Zubair Ul Amin
Zubair Ul Amin - avatar
7 ответов
+ 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
4th Dec 2020, 8:32 AM
NavyaSri
NavyaSri - avatar
+ 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.
3rd Dec 2020, 1:47 PM
NavyaSri
NavyaSri - avatar
+ 2
Zubair Ul Amin YOU : I'm taking about multilevel inheritance . . But, you used single inheritance..(one parent ,one child class)
4th Dec 2020, 8:41 AM
NavyaSri
NavyaSri - avatar
0
Navya Sri but when i pass value through object it call parameterize constructor of Derived class
3rd Dec 2020, 2:21 PM
Zubair Ul Amin
Zubair Ul Amin - avatar
0
Aysha Simra I'm taking about multilevel inheritance
3rd Dec 2020, 3:49 PM
Zubair Ul Amin
Zubair Ul Amin - avatar