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

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

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

    posts - 134,comments - 22,trackbacks - 0
    http://www.devx.com/tips/Tip/13625

    Deep Copy and Shallow Copy
    The terms "deep copy" and "shallow copy" refer to the way objects are copied, for example, during the invocation of a copy constructor or assignment operator. In a deep copy (also called "memberwise copy"), the copy operation respects object semantics. For example, copying an object that has a member of type std::string ensures that the corresponding std::string in the target object is copy-constructed by the copy constructor of class std::string.
     
    class A
    {
    string s;
    };
    A a;
    A b;
    a=b; //deep copy

    When assigning b to a, the compiler-generated assignment operator of class A first invokes the assignment operator of class std::string. Thus, a.s and b.s are well-defined, and they are probably not binary-identical. On the other hand, a shallow copy (also called "bitwise copy") simply copies chunks of memory from one location to another. A memcpy() operation is an example of a shallow copy. Because memcpy() does not respect object semantics, it will not invoke the copy constructor of an object. Therefore, you should never use memcpy() to copy objects. Use it only when copying POD (Plain Old Data) types: ints, floating point numbers, and dumb structs.

    --------------------------------------------------------------------

    http://www.uow.edu.au/~lukes/TEXTBOOK/notes-cpp/oop-condestructors/shallowdeepcopy.html

    A shallow copy of an object copies all of the member field values. This works well if the fields are values, but may not be what you want for fields that point to dynamically allocated memory. The pointer will be copied. but the memory it points to will not be copied -- the field in both the original object and the copy will then point to the same dynamically allocated memory, which is not usually what you want. The default copy constructor and assignment operator make shallow copies.

    A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. To make a deep copy, you must write a copy constructor and overload the assignment operator, otherwise the copy will point to the original, with disasterous consequences.

     原文地址 http://www.uow.edu.au/~lukes/TEXTBOOK/notes-cpp/oop-condestructors/shallowdeepcopy.html
    posted on 2009-12-10 15:44 何克勤 閱讀(217) 評論(0)  編輯  收藏 所屬分類: C/C++
    主站蜘蛛池模板: 免费电影在线观看网站| 91黑丝国产线观看免费| 国产色婷婷精品免费视频| 亚洲日韩国产精品乱-久| 最近免费视频中文字幕大全| 亚洲av无码专区国产乱码在线观看| 国产精品无码免费专区午夜| 亚洲伊人成无码综合网| 91精品成人免费国产| 亚洲精品高清无码视频| 久久99精品国产免费观看| 亚洲国产精品自在在线观看| 最近免费2019中文字幕大全| 亚洲一级黄色大片| 女人18一级毛片免费观看| 在线播放亚洲精品| 国产亚洲老熟女视频| 久久九九全国免费| 久久精品国产亚洲AV嫖农村妇女| 日本免费网站视频www区| 亚洲一线产区二线产区区| 午夜亚洲国产成人不卡在线| 一个人免费观看www视频| 亚洲成年轻人电影网站www| 久久受www免费人成_看片中文| 亚洲色偷偷综合亚洲av78| 亚洲精品视频免费观看| 免费毛片a线观看| 亚洲精品一二三区| 国产精品V亚洲精品V日韩精品| 免费国产成人午夜在线观看| 亚洲AV无码久久久久网站蜜桃| 国产免费观看黄AV片| 久久青草精品38国产免费| 中文文字幕文字幕亚洲色| 亚洲AV无码乱码在线观看| 久久国产免费一区二区三区| 亚洲欧美日韩中文字幕一区二区三区| 亚洲中久无码不卡永久在线观看| 国产成人精品无码免费看| 另类小说亚洲色图|