<分区>
在下面的程序中,我想从一个基类派生一个类。在我的代码中,一切似乎都很好。但是,我收到以下程序中显示的错误。请解释错误的原因,以及如何更正它。
#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);
}
这是错误:
Output:
error: no matching function for call to 'Base::Base()
Note: candidate expects 1 argument, 0 provided