#include <iostream>
using namespace std;
class Point
{
public:
Point():m_x(0),m_y(0),m_z(0){cout<<"构造函数1执行!"<<endl;}
Point(int x,int y):m_x(x),m_y(y),m_z(0){cout<<"构造函数2执行!"<<endl;}
Point(int x,int y,int z):m_x(x),m_y(y),m_z(z){cout<<"构造函数3执行!"<<endl;}
Point(const Point &p):m_x(p.m_x),m_y(p.m_y),m_z(p.m_z)
{
cout<<"拷贝构造函数执行!"<<endl;
}
~Point(){cout<<"析构函数执行!"<<*this<<endl;}
friend ostream & operator<<(ostream &out,const Point &p);
private:
int m_x;
int m_y;
int m_z;
};
ostream & operator<<(ostream &out,const Point &p)
{
out<<p.m_x<<" "<<p.m_y<<" "<<p.m_z<<endl;
return out;
}
Point fun(Point p)
{
return p;
}
int main()
{
Point p1;
Point p2(10,10);
Point p3(10,10,10);
Point p4(p3);
fun(p3);
return 0;
}
using namespace std;
class Point
{
public:
Point():m_x(0),m_y(0),m_z(0){cout<<"构造函数1执行!"<<endl;}
Point(int x,int y):m_x(x),m_y(y),m_z(0){cout<<"构造函数2执行!"<<endl;}
Point(int x,int y,int z):m_x(x),m_y(y),m_z(z){cout<<"构造函数3执行!"<<endl;}
Point(const Point &p):m_x(p.m_x),m_y(p.m_y),m_z(p.m_z)
{
cout<<"拷贝构造函数执行!"<<endl;
}
~Point(){cout<<"析构函数执行!"<<*this<<endl;}
friend ostream & operator<<(ostream &out,const Point &p);
private:
int m_x;
int m_y;
int m_z;
};
ostream & operator<<(ostream &out,const Point &p)
{
out<<p.m_x<<" "<<p.m_y<<" "<<p.m_z<<endl;
return out;
}
Point fun(Point p)
{
return p;
}
int main()
{
Point p1;
Point p2(10,10);
Point p3(10,10,10);
Point p4(p3);
fun(p3);
return 0;
}