Posted on 2012-09-24 10:47
盛勝 閱讀(288)
評論(0) 編輯 收藏 引用 所屬分類:
vc++深入詳解
#include<iostream.h>
class point
{
public:
int x;
int y;
point()
{
x=0;
y=0;
}
point(int a,int b)
{
x=a;
y=b;
}
void output()
{
cout<<x<<endl<<y<<endl;
}
void input(int x,int y)
{
this->x=x;
this->y=y;
}
}
void main()
{
point pt(5,5);
pt.input(10,10);
pt.output();
}
輸出結果為10
10
如果把this指針去掉則為5
5
在使用構造函數時注意是否需要釋放內存。~構造函數名()利用析構函數解決內存泄漏問題。