已采纳回答 / 小蚂蚁1024
#include <iostream>using namespace std;class Coordinate{ public: Coordinate(int x, int y) { // 设置X,Y的坐标 m_iX=x; m_iY=y; } // 实现常成员函数 void printInfo() const { cout<<"("<<m_iX<<","<...
2016-07-29
#include <iostream>
using namespace std;
class Coordinate
{
public:
Coordinate(int x, int y)
{
m_iX=x;
m_iY=y;
}
public:
int m_iX;
int m_iY;
};
int main(void)
{
Coordinate *p=new Coordinate(3,5);
cout <<"("<<p->m_iX<<","<<p->m_iY<<)" << endl;
delete p;
p=NULL;
return 0;
}
using namespace std;
class Coordinate
{
public:
Coordinate(int x, int y)
{
m_iX=x;
m_iY=y;
}
public:
int m_iX;
int m_iY;
};
int main(void)
{
Coordinate *p=new Coordinate(3,5);
cout <<"("<<p->m_iX<<","<<p->m_iY<<)" << endl;
delete p;
p=NULL;
return 0;
}
最赞回答 / 冰海
打上system("pause")之后呢,是不是就跟老师的一样了,,没有system(“pause”),应该是程序自动退出,之后销毁两次实例,所有多出来了两个析构函数的打印文本
2016-07-29
已采纳回答 / 慕粉3649499
coordinate coor[3]={coordinate(1,2),coordinate(3,4),coordinate(5,6)};//对每个成员调用构造函数初始化,在之前要有相应的构造函数
2016-07-24