<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-348  評論-598  文章-0  trackbacks-0
    void ?fu(X *& ?x)
    {
    ????x
    = new ?X();
    ????cout
    <<& x << endl;
    }

    int ?main()
    {

    ????X
    * ?c = NULL;
    ????
    ????fu(c);
    ????cout
    <<& c << endl;
    ????c
    -> display();


    ????
    return ? 0 ;
    }

    參數帶引用的話只可以改變參數的值的,也和雙指針一樣,但貌似傳遞引用更加保險,不會因為疏忽而改變了指針的指針的值
    void?fu(X**?x)
    {
    ????
    *x=new?X();
    ????cout
    <<*x<<endl;
    }

    int?main()
    {

    ????X
    *?c=NULL;
    ????
    ????fu(
    &c);
    ????cout
    <<c<<endl;
    ????c
    ->display();


    ????
    return?0;
    }

    Pass-by-Reference versus Pass-by-Value
    Pass-by-reference is required when you want to modify the parameter and see those changes reflected
    in the variable argument to the function or method However, you should not limit your use of pass-byreference
    to only those cases. Pass-by-reference avoids copying the argument to the function, providing
    two additional benefits in some cases:
    1. Efficiency: large objects and structs could take a long time to copy. Pass-by-reference passes
    only a pointer to the object or struct into the function.
    2. Correctness: not all objects allow pass-by-value. Even those that do allow it might not support
    deep copying correctly. As you learned in Chapter 9, objects with dynamically allocated memory
    must provide a custom copy constructor in order to support deep copying.
    If you want to leverage these benefits, but do not want to allow the original objects to be modified, you
    can mark the parameters const. This topic is covered in detail later in this chapter.
    These benefits to pass-by-reference imply that you should use pass-by-value only for simple built-in
    types like int and double for which you don’t need to modify the arguments. Use pass-by-reference in
    all other cases.

    ---------------------------------------------------------
    專注移動開發

    Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
    posted on 2007-03-17 11:20 TiGERTiAN 閱讀(344) 評論(0)  編輯  收藏 所屬分類: C/C++

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 国产无遮挡无码视频免费软件| caoporn成人免费公开| 2019中文字幕在线电影免费| 亚洲乳大丰满中文字幕| 久久最新免费视频| 久久亚洲AV无码精品色午夜麻| 免费精品久久天干天干| 国产亚洲成av人片在线观看| 免费在线观影网站| 亚洲视频在线视频| 中国在线观看免费国语版| 亚洲欧美国产欧美色欲| 国产一区视频在线免费观看| 一本大道一卡二大卡三卡免费| 亚洲五月综合缴情在线观看| 免费无码一区二区三区| 国产成人精品亚洲日本在线 | 国产成人免费AV在线播放| 永久亚洲成a人片777777 | 在线观看免费视频资源| 亚洲制服丝袜第一页| 精品国产免费观看久久久| 日韩免费在线中文字幕| 亚洲乱码国产一区三区| 久久精品国产免费观看| 亚洲人成网站在线在线观看| 亚洲日韩国产AV无码无码精品| 国产美女a做受大片免费| 羞羞视频免费网站在线看| 久久久久亚洲精品无码蜜桃| 国产在线国偷精品产拍免费| 高清免费久久午夜精品| 在线观看亚洲av每日更新| 久久久久久国产精品免费无码| 中文字幕亚洲码在线| 中文字幕精品亚洲无线码一区| 99精品在线免费观看| 国产精品亚洲专区在线播放| 亚洲福利在线视频| 国产男女猛烈无遮档免费视频网站| 国产日韩AV免费无码一区二区|