/*
* point.cpp
*
* Created on: Dec 1, 2013
* Author: gaojie
*/
#include <iostream>
using namespace std;
class Point3 {
private :
int x ;
int y ;
int z ;
public:
Point3();
~Point3();
Point3(int x, int y, int z);
void Print() const {
cout << "x:" << x <<", y:"<<y <<", z:"<<z<<endl;
}
int getX() const {
return x;
}
int getY() const {
return y;
}
int getZ() const {
return z;
}
};
Point3::Point3(){
x = 10,
y = 20;
z = 30;
}
//析构函数, 对象销毁时调用
Point3::~Point3(){
x = 0; y =0; z = 0;
cout << "destory" <<endl;
}
Point3::Point3(int x, int y, int z) {
this->x = x;
this->y = y;
this->z = z;
};
int main(void){
//创建local变量
Point3 p1(1, 3, 5);
p1.Print();
//创建堆对象(malloc)
Point3* p = new Point3(5, 15, 25);
p->Print();
delete p;
return 0;
}