一个诡异的错误(声明类时的编译错误)

N0TEAR 2008-11-04 02:21:34

class zPoint
{
public:
zPoint(int x=0, int y=0):xPos(x), yPos(y) {}
int getPosX() const { return xPos; }
int getPosY() const { return yPos; }
bool pointRange(int x, int y) const;
bool setPoint(int x, int y);
bool drawPoint();
protected:
int xPos, yPos;
};

class zRect : public zPoint
{
public:
zRect(zPoint pa, zPoint pb):opposite[0].xPos(pa.xPos), //错误指向这一行
opposite[0].yPos(pa.yPos),
opposite[1].xPos(pb.xPos),
opposite[1].xPos(pb.yPos) {}
bool rectRange(int x, int y) const;
bool setRect(zPoint pa, zPoint pb);
bool drawRect();
private:
zPoint opposite[2];


编译时报错error C2059: syntax error : '['

哪里出错了?
...全文
113 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
太乙 2008-11-04
  • 打赏
  • 举报
回复
对数组的初始化不要拿到初始化列表里!
mingguang7213 2008-11-04
  • 打赏
  • 举报
回复
语法错误,不支持这样写。构造函数初始化列表不支持数组附值
xhs_lh04 2008-11-04
  • 打赏
  • 举报
回复
实现个zPoint拷贝构造函数zPoint(zPoint &A)

zRect(zPoint pa, zPoint pb):opposite[0](pa),opposite[1](pb) {};

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧