m_pcoorA = new coordinate(x1, y1); //这是在干啥啊?这里为什么用到coordinate()???
m_pcoorB = new coordinate(x2, y2);
cout << "line()" << endl;
m_pcoorB = new coordinate(x2, y2);
cout << "line()" << endl;
2016-12-25
已采纳回答 / qq_shuaishuaiha_0
同学你好,截图中的这种方法使列表初始化,常量成员赋值就是要这种方法。你看下封装上篇其中的6-4C++构造函数初始化列表,想必你就更清楚了。
2016-12-22
已采纳回答 / 慕工程2528034
构造函数的初始化列表如下:对象名:对象名(成员变量1初始化,成员变量2初始化.......):成员变量1(初始化值),成员变量2(初始化值2)例如:一个类A,有两个成员变量(int)x,y;A的构造函数可以写成这样:A:A(int m,int n):x(m),y(n){}
2016-12-22
....
// 打印坐标的函数
void printInfo()
{
cout << "(" << m_iX << "," << m_iY << ")\n";
}
public:
int m_iX;
int m_iY;
};
int main(void)
{
//定义对象数组
Coordinate coorArr[2];
coorArr[0].m_iX = 1;
coorArr[0].m_iY = 2;
coorArr[1].m_iX = 3;
coorArr[1].m_iY = 4;
// 打印坐标的函数
void printInfo()
{
cout << "(" << m_iX << "," << m_iY << ")\n";
}
public:
int m_iX;
int m_iY;
};
int main(void)
{
//定义对象数组
Coordinate coorArr[2];
coorArr[0].m_iX = 1;
coorArr[0].m_iY = 2;
coorArr[1].m_iX = 3;
coorArr[1].m_iY = 4;
Coordinate *p = new Coordinate[3];
p->m_iX = 7;
p->m_iY = 9;
// p = p+1; // p = p + 1;
(p+1)->m_iX = 11;
(p+1)->m_iY = 17;
// p = p+1;
(p+2)->m_iX = 3;
(p+2)->m_iY = 2;
p->m_iX = 7;
p->m_iY = 9;
// p = p+1; // p = p + 1;
(p+1)->m_iX = 11;
(p+1)->m_iY = 17;
// p = p+1;
(p+2)->m_iX = 3;
(p+2)->m_iY = 2;
2016-12-21
已采纳回答 / qq_梵蒂冈_1
用的话就是这样line::line(int x1,int y1,int x2,int y2):m_iA(new coordinate(x1,y1)),m_iB(new coordinate(x2,y2)){cout<<"line()"<<endl;}用不用都可以的,看自己习惯。
2016-12-21