Does a copy constructor/operator/function need to make clear which copy variant it implements?

前端 未结 4 645
故里飘歌
故里飘歌 2021-01-11 12:54

Yesterday I asked a question about copying objects in C#, and most answers focussed on the difference between deep copy and shallow copy, and the fact that it

4条回答
  •  伪装坚强ぢ
    2021-01-11 13:04

    Most C++ programmers do not use the terms "shallow copy" and "deep copy" for the very good reason that there is only normally one way to copy an object. This is particularly true in C++ because the compiler uses the copy constructor in many situations where the programmer could tell it which copy constructor to use - for example:

    void f( std::string s );
    

    there is no way of telling the compiler how to copy the string.

提交回复
热议问题