+ 9
Confusion in const and &...
Did anyone notice in the syntax for copy constructor... class_name(const class_name &obj_name) const and reference is used at the same time...I get that we dont wanna change the original argument passed to the ctor that's why we used the const but what about the reference...the only reason of using it would be so that we can CHANGE the original argument...! Doesn't const and reference contradicts each other ._0
2 Answers
+ 6
Thanks that clears a lot of the confusions :)
+ 2
The other reason we would pass by reference is speed. By using a constant reference we're telling the user of the function "we're using references just for speed, don't worry about side effects".