Copy Constructors - What, Why, and when to use one...

0 corbin mckeeth · April 12, 2015
I'm supposed to use copy constructors in an assignment.  I really have no clue what they are, why we need them, or when to use one.  After the surfing the web a bit, I see how to make one, but that's about it.  Thanks...

Post a Reply


Oldest  Newest  Rating
+1 Franz Schmidt · April 12, 2015
OK had to do some research too but lets see if I can explain it to you:

if you have an object and say it has a variable with a value of 3...
if you want to make another object, which has the same value of this variable you would need to get the value from this object and than you would need to pass it to the new created object 
you can use a copy construcor

Lets give an example:
I have th object test from the class test_vars with a variable var = 3:
and if I want to copy this object WITHOUT a copy constructor i would need to do this.
test_vars test2;
//here i get the value of test with the get_value funktion and pass it into test2 with the set_value funktion

and if i use copy constructor i only need to do this:

test_vars test2(test);

and I'm done.
See the difference it is way more clear than to get values and set values...
Here is a wikipedia article... sorry but its on german but the englisch version was really bad explained, hope you can figure it out.:D
0 corbin mckeeth · April 13, 2015
Awesome thanks for explaining that!
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator