您的位置:首页 > 编程语言 > C语言/C++

C++ 用new动态创建对象

2014-02-28 16:12 204 查看
#include<iostream>

using namespace std;

class TPoint1{
int x, y;
public:
TPoint1(int x1, int y1){//构造函数
x = x1;
y = y1;
}

void dispoint(){//输出点的信息
cout<<"("<<x<<", "<<y<<")"<<endl;
}
};

int main()
{
TPoint1 a(12,6);
TPoint1* p = new TPoint1(5, 12);
cout<<"First point: ";
a.dispoint();
cout<<"second point: ";
p->dispoint();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: