c++为什么这里没有调用两次拷贝够造函数
/*
* File: main.cpp
* Author: chujiangke
*
* Created on 2013年4月1日, 下午11:04
*/
#include <cstdlib>
#include <iostream>
using namespace std;
/*
*
*/
class point
{
int a;
int b;
//point(point&);
public:
point(int b,int a){cout<<"contructor with argc"<<endl;this->a=a;this->b=b;}
point(){cout<<"contructor without argc "<<endl;a=0;b=0;}
point &operator=(const point a){cout<<"copy whit ="<<endl;this->a=a.a;this->b=a.b;return *this;}
point(const point &obj){cout<<"copy contructor"<<endl;a=obj.a;b=obj.b;}
int get_a(){return a;}
int get_b(){return b;}
};
point funciton1(point a)
{
point *b=new point;
cout<<"11111111111111111"<<endl;
*b=a;
cout<<"22222222222222222"<<endl;
return *b;
}
int main(int argc, char** argv) {
point a(11,12);
point b;
b=funciton1(a);
cout<<",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:"<<endl;
point c=funciton1(a);
cout<<b.get_a();
return 0;
}
contructor with argc
contructor without argc
copy contructor
contructor without argc
11111111111111111
copy contructor
copy whit =
22222222222222222
copy contructor
copy whit =
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:
copy contructor
contructor without argc
11111111111111111
copy contructor
copy whit =
22222222222222222
copy contructor//function构造临时变量要一次,初始化c也要一次拷贝啊
12