In this post, we will see C++ Passing Parameters to Base Class Constructors | Passing values to base class constructor in C++
Program Code (inheritance7.cpp)
/*C++ Passing Parameters to Base Class Constructors*/
#include<iostream>
using namespace std;
class A
{
public:
A()
{
cout<<"In A class constructor"<<endl;
}
A(int x)
{
cout<<"In A class constructor with value="<<x<<endl;
}
};
class B: public A
{
public:
B()
{
cout<<"In B class constructor"<<endl;
}
B(int y):A(7)
{
cout<<"In B class constructor with value="<<y<<endl;
}
};
int main()
{
B obj;
}
Watch following video:
Watch on YouTube: https://www.youtube.com/watch?v=oTGUKXH2JpA
No comments:
Post a Comment