Question copy constructor vs parameterized constructor

Keith_K

New member
Joined
Mar 15, 2021
Messages
3
Programming Experience
Beginner
In what case(s) would it be wise to use a copy constructor instead of a parameterized constructor and vise-versa?
 
As a quick aside, C# does not have a copy constructor like C++. You could implement a C# constructor to act like a C++ copy constructor, you don't get one for free without putting in some effort.
 
I'm not into C++, but read it acts like a shallow copy, only a user defined constructor can do a deep copy. Hence the tip about MemberwiseClone.
You also have ICloneable Interface (System) where you're supposed to implement cloning beyond MemberwiseClone, but since the interface doesn't mandate the level of copy you probably should write a constructor that takes another instance as parameter and document its behaviour.
 
Back
Top Bottom