<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++
    主站蜘蛛池模板: 黄色短视频免费看| 亚洲av成人中文无码专区| a毛片全部播放免费视频完整18| 免费v片视频在线观看视频| 亚洲色偷偷偷综合网| 免费观看的毛片大全| 亚洲av午夜精品无码专区| 久久久久久久91精品免费观看| 亚洲国产精品成人久久久| 国产卡一卡二卡三免费入口| 亚洲三级在线视频| 浮力影院第一页小视频国产在线观看免费 | 国产亚洲精久久久久久无码77777| 免费激情网站国产高清第一页| 四虎影视在线永久免费看黄| 人妖系列免费网站观看| 亚洲人成网77777色在线播放| a毛片在线看片免费| 亚洲精品国产成人| 成人免费视频网址| 一级做a爰黑人又硬又粗免费看51社区国产精品视 | 最近2019免费中文字幕6| 亚洲AV无码久久久久网站蜜桃| 在线视频免费观看高清| 国产AV日韩A∨亚洲AV电影| 亚洲精品高清在线| 95老司机免费福利| 亚洲成AV人片高潮喷水| 久久精品国产亚洲精品| 999久久久免费精品播放| 在线观看日本亚洲一区| 亚洲精品WWW久久久久久| 毛片在线全部免费观看| 亚洲午夜在线播放| 亚洲精品中文字幕乱码三区 | 免费国产在线视频| 欧洲 亚洲 国产图片综合| 亚洲国产精品一区二区第一页免| 久久99热精品免费观看牛牛| 亚洲AV成人一区二区三区在线看 | 精品香蕉在线观看免费|