Constructor for 'Master' must explicitly initialize the base class 'Hight_student' which does not have a default constructor
时间: 2023-12-22 18:06:33 浏览: 306
这个错误是因为你在派生类(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
}
};
```
在上面的例子中,我们使用成员初始化列表调用了基类的构造函数,以确保派生类对象中的基类子对象能够被正确地初始化。
相关问题
Constructor for 'Model' must explicitly initialize the member 'shader' which does not have a default constructor
The error message you are encountering suggests that there is a member variable called 'shader' in the 'Model' class that does not have a default constructor, and it needs to be explicitly initialized in the constructor of the 'Model' class.
To resolve this issue, you should add an explicit initialization for the 'shader' member variable in the constructor of the 'Model' class. You can do this by using an initializer list.
For example:
```cpp
class Model {
private:
Shader shader; // Assuming 'Shader' is the type of the 'shader' member variable
public:
Model() : shader(/* arguments for shader's constructor */) {
// Constructor code
}
};
```
Replace `Shader` with the actual type of the 'shader' member variable, and provide the necessary arguments for the 'shader' constructor within the initializer list.
By explicitly initializing the 'shader' member variable in the constructor, you ensure that it is properly initialized before any other code in the constructor executes.
阅读全文