【发布时间】:2016-01-16 13:01:29
【问题描述】:
为 SquareValue 设置以下构造函数的正确方法是什么? 我收到以下错误:
“SquareValue 的构造函数必须显式初始化没有默认构造函数的成员“square””
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
class Square {
public:
int X, Y;
Square(int x_val, int y_val) {
X = x_val;
Y = y_val;
}
};
class SquareValue {
public:
Square square;
int value;
SquareValue(Square current_square, int square_value) {
square = current_square;
value = square_value;
}
};
我曾计划将 Square() 构造函数传递给 SquareValue 构造函数。
【问题讨论】:
标签: c++ xcode object constructor member