【发布时间】:2022-01-04 05:28:38
【问题描述】:
我正在用 C++ 制作战舰棋盘游戏,但在访问我在其中一个类中声明的结构时遇到问题。
class Ship {
typedef struct {
int x;
int y;
}Start;
typedef struct {
int x;
int y;
}End;
bool isAfloat;
Start _start;
End _end;
public:
Ship(int start_x, int start_y, int end_x, int end_y);
我尝试了各种可以想到的方式,但我显然在这里遗漏了一些东西。
Ship::Ship(int start_x, int start_y, int end_x, int end_y):
_start.x(start_x), //error, expected "(" where the "." is
_start.y(start_y),
_start.x(end_x),
_end.y(end_y)
{}
任何帮助表示赞赏。
【问题讨论】:
标签: c++ class struct initialization aggregate-initialization