c++实例研究

从0开始

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  104 随笔 :: 0 文章 :: 20 评论 :: 0 Trackbacks

 运行的结果会很有趣的。

#include <cstdlib>
#include 
<iostream>
using namespace std;

class Foo
{
public:
    Foo()
{cout<<"construct"<<endl;}
    
~Foo(){cout<<"destruct"<<endl;}
    Foo(
const Foo& other){cout<<"copy"<<endl;}
}
;

int func1()
{
    Foo f;
    
return 0;
}


Foo func2()
{
    Foo f;
    
return f;
}


Foo
& func3()
{
    Foo f;
    
return f;
}


int main()
{
    func1(); 
//构建,析构 
    cout<<endl;
    
int i = func1(); //编译器相关 
    cout<<endl;
    func2(); 
//构建,析构 
    cout<<endl;
    Foo f2 
= func2(); //编译器相关 
    cout<<endl;
    func3(); 
//构建,析构 
    cout<<endl;
    Foo f3 
= func3(); //编译器相关 
    system("PAUSE");
    
return 0;
}

posted on 2010-05-05 11:09 elprup 阅读(210) 评论(0)  编辑 收藏 引用 所属分类: c++实例

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理