gpt4 book ai didi

C++ 继承 : Error: candidate expects 1 argument, 0 提供

转载 作者:行者123 更新时间:2023-11-30 05:07:44 29 4
gpt4 key购买 nike

<分区>

在下面的程序中,我想从一个基类派生一个类。在我的代码中,一切似乎都很好。但是,我收到以下程序中显示的错误。请解释错误的原因,以及如何更正它。

#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

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com