?? 6_16.cpp
字號:
//6_16.cpp
#include<iostream>
using namespace std;
class Point
{ public:
Point()
{ X=Y=0; cout<<"Default Constructor called."<<endl; }
Point(int xx,int yy)
{ X=xx; Y=yy; cout<< "Constructor called."<<endl; }
~Point()
{ cout<<"Destructor called."<<endl; }
int GetX() {return X;}
int GetY() {return Y;}
void Move(int x,int y)
{ X=x; Y=y; }
private:
int X,Y;
};
void main()
{
cout<<"Step One:"<<endl;
Point *Ptr1=new Point; //動態創建對象,沒有給出初值,因此調用缺省構造函數
delete Ptr1; //刪除對象,自動調用析構函數
cout<<"Step Two:"<<endl;
Ptr1=new Point(1,2); //動態創建對象,并給出初值,因此調用有形參的構造函數
delete Ptr1; //刪除對象,自動調用析購函數
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -