C:\Users\hoob\Desktop\friend.cpp(27) : error C2059: syntax error : 'constant' 为什么?

#include<iostream.h>
#include<math.h>
class point
{
private:
int x,y;
point (int a,int b)
{
x=a;
y=b;
}
point ()
{
x=0;
y=0;
}
void disp()
{
cout << "(x,y)" << "("<<x<<","<<y<<")"<<endl;
}
friend class line;
};

class line
{
public:
point p1(1,1),p2(2,2);
//point p2(2,2);
line()
{
// p1.x = 1;
// p1.y = 1;
// p2.x = 2;
// p2.y = 2;
}
void disp()
{
p1.disp();
p2.disp();
}
};

void main()
{
line l1;
l1.disp();
}

在类定义中不能实例化类对象!!
只能在构造函数中进行对象变量实例化!
温馨提示:答案为网友推荐,仅供参考
相似回答