面试时被问过这个问题,编译后还是没看懂结果。。。
我有以下课程:
class Point
{
public:
Point(double x = 0, double y = 0) { m_X = x; m_Y = y; }
double m_X, m_Y;
};
main.cpp 是:
int main()
{
double a = 1, r = 1, xCoord = 5, yCoord = 7;
Point p = (a+r*xCoord , a+r*yCoord);
cout<<"X = "<<p.m_X<<" Y = "<<p.m_Y<<endl;
return 0;
}
类 p 的数据成员正在获取值:
m_X = a+r*yCoord, m_Y = 0
现在,这是为什么呢?