标题:求助
取消只看楼主
lscmxl
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-6-12
 问题点数:0 回复次数:1 
求助
分析一下这段程序的输出 (Autodesk)
    class B
    {
    public:
        B()
        {
            cout<<"default constructor"<<endl;
        }
        ~B()
        {
            cout<<"destructed"<<endl;
         }
        B(int i):data(i)    //B(int) works as a converter ( int -> instance of  B)
        {
            cout<<"constructed by parameter " << data <<endl;
        }
    private:
        int data;
    };
    B Play( B b)
    {
        return b ;
    }
    (1)                                         results:
    int main(int argc, char* argv[])            constructed by parameter 5
    {                                           destructed  B(5)形参析构
        B t1 = Play(5); B t2 = Play(t1);       destructed  t1形参析构
        return 0;                   destructed  t2 注意顺序!
     }                                          destructed  t1
    (2)                                         results:
    int main(int argc, char* argv[])            constructed by parameter 5
    {                                           destructed  B(5)形参析构
        B t1 = Play(5); B t2 = Play(10);       constructed by parameter 10
        return 0;                   destructed  B(10)形参析构
    }                                           destructed  t2 注意顺序!
                                                destructed  t1

上面程序究竟是怎么个走法?红色标记处是什么意思?请高手指教!
搜索更多相关主题的帖子: default private public 
2008-10-15 11:13
lscmxl
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-6-12
得分:0 
红色标记处的意思懂了。谢谢
那程序调用流程呢,谁来解答一下。
2008-10-16 13:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-238367-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.184991 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved