<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++

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


    網站導航:
     
    主站蜘蛛池模板: 日本特黄特色aa大片免费| 日韩在线免费视频| 亚洲精品综合久久| 理论片在线观看免费| 波多野结衣中文一区二区免费| 亚洲AV一区二区三区四区| 日韩免费毛片视频| 国产AV无码专区亚洲AV麻豆丫| 国产一级理论免费版| 免费一级做a爰片久久毛片潮| 亚洲第一黄色网址| 你是我的城池营垒免费看| 久久亚洲AV午夜福利精品一区| 日日麻批免费40分钟无码| 亚洲网址在线观看| 欧美三级在线电影免费| 国产成人综合亚洲绿色| 中文字幕在亚洲第一在线| 久别的草原电视剧免费观看| 亚洲狠狠狠一区二区三区| 在线观看免费为成年视频| 羞羞视频免费网站日本| 久久乐国产精品亚洲综合| 久久aa毛片免费播放嗯啊| 天天爽亚洲中文字幕| 亚洲中久无码不卡永久在线观看| 热99RE久久精品这里都是精品免费| 亚洲欧洲日产国码二区首页| 永久久久免费浮力影院| 9久热精品免费观看视频| 亚洲制服在线观看| 亚洲熟妇少妇任你躁在线观看无码| 男人j进入女人j内部免费网站| 亚洲偷自拍另类图片二区| 精品国产香蕉伊思人在线在线亚洲一区二区 | 亚洲人成色777777老人头| 久久久亚洲精品蜜桃臀| 美女裸身网站免费看免费网站| 夜夜爽妓女8888视频免费观看| 99亚洲精品高清一二区| 亚洲AV之男人的天堂|