类A以数组的形式在类B中,且类A不存在默认构造函数,在类B中如何进行初始化呢?
以下是我部分源代码。
class Croad {//格子路类
public:
Croad(int x1_, int y1_, int x2_, int y2_,int func_=0) {
rx1 = x1_;
ry1 = y1_;
rx2 = x2_;
ry2 = y2_;
func = func_;
}
void show(){
rectangle(rx1, ry1, rx2, ry2);
}
void roadFunction() {
}
private:
RECT site;
int func;
int rx1, ry1, rx2, ry2;
};
class Cmap {//地图类
public:
Cmap(){
pts[0] = { X_EDGE + 1 * LAND + 2 * MARGIN,Y_EDGE + 1 * LAND + 2 * MARGIN };
pts[1] = { X_EDGE + 1 * LAND + 2 * MARGIN,Y_EDGE + 7 * LAND + 14 * MARGIN };
pts[2] = { X_EDGE + 4 * LAND + 8 * MARGIN,Y_EDGE + 7 * LAND + 14 * MARGIN };
pts[3] = { X_EDGE + 4 * LAND + 8 * MARGIN,Y_EDGE + 9 * LAND + 18 * MARGIN };
pts[4] = { X_EDGE + 8 * LAND + 16 * MARGIN,Y_EDGE + 9 * LAND + 18 * MARGIN };
pts[5] = { X_EDGE + 8 * LAND + 16 * MARGIN,Y_EDGE + 7 * LAND + 14 * MARGIN };
pts[6] = { X_EDGE + 11 * LAND + 22 * MARGIN,Y_EDGE + 7 * LAND + 14 * MARGIN };
pts[7] = { pts[6].x,pts[0].y };
pts[8] = { pts[5].x,pts[7].y };
pts[9] = { pts[8].x,Y_EDGE + 3 * LAND + 6 * MARGIN };
pts[10] = { X_EDGE + 5 * LAND + 10 * MARGIN,pts[9].y };
pts[11] = { pts[10].x,pts[0].y };
int temp = 1 * LAND + 2 * MARGIN;
ptsIn[0] = { pts[0].x + temp,pts[0].y + temp };
ptsIn[1] = { pts[1].x + temp,pts[1].y - temp };
ptsIn[2] = { pts[2].x + temp,pts[2].y - temp };
ptsIn[3] = { pts[3].x + temp,pts[3].y - temp };
ptsIn[4] = { pts[4].x - temp,pts[4].y - temp };
ptsIn[5] = { pts[5].x - temp,pts[5].y - temp };
ptsIn[6] = { pts[6].x - temp,pts[6].y - temp };
ptsIn[7] = { pts[7].x - temp,pts[7].y + temp };
ptsIn[8] = { pts[8].x + temp,pts[8].y + temp };
ptsIn[9] = { pts[9].x + temp,pts[9].y + temp };
ptsIn[10] = { pts[10].x - temp,pts[10].y + temp };
ptsIn[11] = { pts[11].x - temp,pts[11].y + temp };
}
void show() {
polygon(pts, 12);
polygon(ptsIn, 12);
}
private:
POINT pts[12];//外圈
POINT ptsIn[12];//里圈
Croad road[16];//格子
};
我尝试使用初始化列表,但是给我报错,