LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   c++ pass-by-value question (https://www.linuxquestions.org/questions/programming-9/c-pass-by-value-question-727053/)

kpachopoulos 05-19-2009 09:21 AM

c++ pass-by-value question
 
Hi,
i have the following question. Say there is a function "void put(Data d)". The parameter is passed-by-value, however how is that in the case of the object of type Data? In order to be passed by value must i define a Data copy constructor first? What happens if i haven't defined it?

Thanks

tuxdev 05-19-2009 09:51 AM

If you don't provide one a copy constructor will be provided for you. It'll do a "memberwise copy", which means a bit copy of of primitives (including pointers), and copy construction of classes. Pretty much the same thing with the assignment operator. For any well designed C++ class you *must* determine the Right Thing for the copy constructor, assignment operator, and destructor. In most cases you'll either define all three or none at all. This principle is called the "Rule of Three".


All times are GMT -5. The time now is 11:56 PM.