// text1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <ctime>
#include <memory>
#include <iostream>
using namespace std ;
class test
{
friend test foo ( double );
public :
test ()
{
memset ( array , 0 , 100 *sizeof ( double ) );
cout << "test constructor " <<'\n' ;
}
~test ()
{
cout << "test deconstructor " << '\n' ;
}
test ( const test &t );
private :
double array [ 100 ];
};
inline test ::test ( const test &t )
{
memcpy ( this , &t , sizeof ( test ) );
cout << "test copy " << '\n' ;
}
test foo ( double val )
{
test local , local2 ;
local .array [ 0 ] = val ;
local .array [ 99 ] = val ;
if (val > -1 )
return local ;
}
int _tmain(int argc, _TCHAR* argv[]) {
test t1 = foo( 2 );
return 0;
}
不开启优化
开启优化后
优化掉了 return 时 的拷贝构造函数,和 析构掉临时 OBJECT,