#include "stdafx.h"
#include <iostream>
using namespace std;
class Point
{
public:
Point(int xx=0,int yy=0)
{
x=xx;
y=yy;
}
Point(Point &p);//复制构造函数基本格式
int getx()
{
return x;
}
int gety()
{
return y;
}
private:
int x,y;
};
Point::Point(Point &p)
{
static int i=0;
x= p.x;
y= p.y;
cout<<"point 复制构造函数"<<i<<"谁调用"<<x<<endl;
i++;
}
void fun1(Point p,Point q,Point t)
{
cout<<p.getx()<<" "<<q.getx()<<" "<<t.getx()<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
Point a(1,2),b(3,4),c(5,6);
fun1(a,b,c);//拷贝构造函数调用顺序为c,b,a;
return 0;
}
在形参与实参结合时调用构造函数的顺序是从后向前的。