county.cpp:13:9: error: constructor for 'County' must explicitly initialize the base class 'Playable' which does not have a default constructor county.h:11:7: note: 'Playable' declared here
时间: 2024-03-23 22:42:45 浏览: 23
这个错误是因为在 `County` 类的构造函数中没有显式调用 `Playable` 类的构造函数,而 `Playable` 类没有默认构造函数。因此,需要在 `County` 类的构造函数初始化列表中调用 `Playable` 类的有参构造函数,传递必要的参数。
例如,如果 `Playable` 类的有参构造函数为 `Playable(int id)`,则 `County` 类的构造函数应该这样写:
```c++
County::County(int id, std::string name) : Playable(id), countyName(name) {
// 其他初始化代码
}
```
其中,`Playable(id)` 表示调用 `Playable` 类的有参构造函数,并传递参数 `id`。另外,需要注意的是,初始化列表中的初始化顺序应该与类定义中声明的顺序一致,否则可能会导致一些意外的问题。
相关问题
Qt:constructor for 'dab::DabAsListNvm' must explicitly initialize the base class 'dab::DabListNvm' which does not have a default constructor
这个问题看起来像是你在使用C++的Qt框架时遇到的一个编译错误。
这个错误的原因是,在你的类`DabAsListNvm`的构造函数中,你没有显式地调用`DabListNvm`的构造函数,而`DabListNvm`没有默认构造函数。
为了解决这个问题,你需要在`DabAsListNvm`的构造函数初始化列表中显式地调用`DabListNvm`的构造函数,并传递所需的参数。例如:
```c++
DabAsListNvm::DabAsListNvm(int arg1, double arg2)
: DabListNvm(arg1) // 显式调用基类构造函数
, m_arg2(arg2)
{
// 构造函数的其他代码
}
```
注意,`DabListNvm`的构造函数必须在`DabAsListNvm`的构造函数初始化列表中的第一个调用。
Constructor for 'Master' must explicitly initialize the base class 'Hight_student' which does not have a default constructor
这个错误是因为你在派生类(Master)的构造函数中没有显式地调用基类(High_student)的构造函数,而基类又没有默认构造函数。解决方法是在派生类的构造函数中使用成员初始化列表来调用基类的构造函数,例如:
```
class Master : public High_student {
public:
Master(int age, int height, int weight) : High_student(age, height, weight) {
// other constructor code here
}
};
```
在上面的例子中,我们使用成员初始化列表调用了基类的构造函数,以确保派生类对象中的基类子对象能够被正确地初始化。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)