When writing the copy ctor for a container (lets say, a dynamic array) should the copy ctor also call the copy ctor of the elements being copied, or should it call copy assignment on each element?
#cplusplus #programming
If copy assignment is ok, then copy ctor can be implemented is terms of copy assignment. Container(const Container& x) { *this = other; } If not... well then it can't be implemented in terms of the other.
-
-
Copy assignment and copy construction have fundamentally different meanings. You should support both where each makes sense. Specifically, copy construction everywhere you can (never assume default construction is trivial) and copy assignment where you’re overwriting values.
Kiitos. Käytämme tätä aikajanasi parantamiseen. KumoaKumoa
-
Lataaminen näyttää kestävän hetken.
Twitter saattaa olla ruuhkautunut tai ongelma on muuten hetkellinen. Yritä uudelleen tai käy Twitterin tilasivulla saadaksesi lisätietoja.