有一点不明白
#include <iostream>using namespace std;
class Point{
public:
Point(int i,int j) {
x=i;
y=j;
cout<<"Point Constructor\n";
}
Point(Point &tempP){
x=tempP.x+3;
y=tempP.y+3;
cout<<"Point Copy_Constructor\n";
}
int getX(){ return x; }
int getY(){ return y; }
~Point(){cout<<"Point Destructor\n";}
void print(){
cout<<"pointX="<<x<<",pointY="<<y<<endl;
}
private:
int x,y;
};
int main(){
Point a1(2,3);
a1.print();
Point a2(a1);
a2.print();
Point *pa=new Point(8,9);
pa->print();
cout<<pa->getY()-pa->getX()<<endl;
delete pa;
return 0;
}
运行结果中的 1 是怎么来的!!求教!
运行出来是:
Point Constructor
pointX=2,pointY=3
Point Copy_Constructor
pointX=5,pointY=6
Point Constructor
pointX=8,pointY=9
1
Point Destructor
Point Destructor
Point Destructor
请按任意键继续. . .