Menu
Forums
Login | Register

Home > Forums > C++ > Pass by Reference in Copy constructor Page :  1 
Pass by Reference in Copy constructor
Hi,

I have received an e-mail asking the following :

message: Why we are using reference in Copy constructor? why not object is pass by value?

This is done intentionally as if you pass the object by value, it would create another copy of the object being copied rather than just using that particular object. This is extremely wasteful as there is no reason why you should not be accessing the original object.

Passing by reference is therefore more efficient than passing by value. Passing by value is only really needed if you want to modify member variables of that object within a method but you do not want those changes to be seen upon leaving the method.

Please let me know if there are any problems.

Regards,
Grant

Home > Forums > C++ > Pass by Reference in Copy constructor Page :  1 

You need to be logged in to reply to this topic.


All Rights Reserved, © Zeus Communications, Multimedia & Development 2004-2005

Read the Disclaimer

Links