base class 'class People' should be explicitly initialized in the copy constructor [-Wextra]怎么解决
时间: 2023-06-27 22:03:02 浏览: 153
这个警告是因为在复制构造函数中没有显式地初始化基类 People。可以通过在初始化列表中显示调用基类的复制构造函数来解决这个警告。
示例代码:
```
class People {
public:
People() {}
People(const People& other) {}
};
class Student : public People {
public:
Student() {}
Student(const Student& other) : People(other) {}
};
```
在上面的代码中,Student 继承了 People 类。在 Student 的复制构造函数中,使用初始化列表显式调用了基类 People 的复制构造函数,以确保正确地复制基类的成员变量。这样就可以解决上述警告。
相关问题
Browserslist: caniuse-lite is outdated. Please run: npx update-browserslist-db@latest Why you should do it regularly: https://github.com/browserslist/update-db#readme Though the "loose" option was set to "false" in your @babel/preset-env config, it will not be used for @babel/plugin-proposal-private-property-in-object since the "loose" mode option was set to "true" for @babel/plugin-proposal-class-properties. The "loose" option must be the same for @babel/plugin-proposal-class-properties, @babel/plugin-proposal-private-methods and @babel/plugin-proposal-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding ["@babel/plugin-proposal-private-property-in-object", { "loose": true }] to the "plugins" section of your Babel config.
这是一条警告信息,告诉你需要更新你的浏览器兼容性列表。更新后,你可以更好地支持最新的浏览器特性。另外,这还提醒你在使用 @babel/preset-env 时,需要保持插件的 "loose" option 一致,否则会出现这个警告。你可以在 Babel 配置文件的 "plugins" 部分中添加 ["@babel/plugin-proposal-private-property-in-object", { "loose": true }] 来解决这个问题。
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
}
};
```
在上面的例子中,我们使用成员初始化列表调用了基类的构造函数,以确保派生类对象中的基类子对象能够被正确地初始化。
阅读全文