+ 1

Copy constructors

Help copy constructors

4th Nov 2018, 3:44 AM
Timothy Allen Johnson II
Timothy Allen Johnson II - avatar
10 Respostas
+ 3
As you may know, the copy constructor is used to create a new object from another existing object. here is an example on how a copy constructor would look like: https://code.sololearn.com/c0STVh9BU3p2/#cpp
4th Nov 2018, 3:41 PM
MO ELomari
MO ELomari - avatar
+ 3
as @Tyrant says the C++ compiler creates a default copy constructor for each class which does a member-wise copy between objects but you need to define your own copy constructor only if the object has pointers or any runtime allocation of the resource.
4th Nov 2018, 5:56 PM
MO ELomari
MO ELomari - avatar
+ 2
Copy constructors are created automatically when you create classes.You dont need to worry about them,well most of the time anyway,...
4th Nov 2018, 4:09 AM
Mensch
Mensch - avatar
+ 2
Well,in that case i think its ok to create a copy constructure..Do you need help creating copy constructures...Im happy to help...
4th Nov 2018, 4:25 AM
Mensch
Mensch - avatar
+ 1
thanks for the example!
4th Nov 2018, 5:17 PM
Timothy Allen Johnson II
Timothy Allen Johnson II - avatar
+ 1
yeah, the copy constructor takes one parameter( reference to the type for which it belongs )
4th Nov 2018, 5:42 PM
MO ELomari
MO ELomari - avatar
+ 1
ok, i like your example better than the text book from my class
4th Nov 2018, 5:44 PM
Timothy Allen Johnson II
Timothy Allen Johnson II - avatar
0
what it you need to define a user defined copy constructor without overwroting previously written data?
4th Nov 2018, 4:17 AM
Timothy Allen Johnson II
Timothy Allen Johnson II - avatar
0
honestly yes... simple examples alwyas help
4th Nov 2018, 4:26 AM
Timothy Allen Johnson II
Timothy Allen Johnson II - avatar
0
so the copy constructor takes an app object as its in parameter?
4th Nov 2018, 5:20 PM
Timothy Allen Johnson II
Timothy Allen Johnson II - avatar