in the following program, I want to derive a class from a base class. In my code everything seems to be OK. However, I am getting error shown in the below program. Please explain the reason for the error, and how to correct it.
#include <iostream>
using namespace std;
struct Base
{
int x;
Base(int x_)
{
x=x_;
cout<<"x="<<x<<endl;
}
};
struct Derived: public Base
{
int y;
Derived(int y_)
{
y=y_;
cout<<"y="<<y<<endl;
}
};
int main() {
Base B(1);
Derived D(2);
}
This is the error:
Output:
error: no matching function for call to 'Base::Base()
Note: candidate expects 1 argument, 0 provided