How to clone object in C++ ? Or Is there another solution?

前端 未结 3 2097
南方客
南方客 2020-12-01 03:48

I wrote a Stack and Queue implementation (Linked List based). There is one stack (bigStack). For example, I separate bigStack (example: stack

3条回答
  •  醉话见心
    2020-12-01 04:17

    In C++ copying the object means cloning. There is no any special cloning in the language.

    As the standard suggests, after copying you should have 2 identical copies of the same object.

    There are 2 types of copying: copy constructor when you create object on a non initialized space and copy operator where you need to release the old state of the object (that is expected to be valid) before setting the new state.

提交回复
热议问题