passing arguments by reference.

Pages: 12
is there an exception where the object is not passed by the reference?


They always pass by value unless you say otherwise.
@ResidentBiscuit: You need to write a copy constructor if the provided by the compiler (member by member copy) is not good enought.
Remember that if you need to define a copy constructor, an assignment operator or a destructor, you will need all of them.

Also try to reuse code. By instance if you want to share resources, use shared_ptr instead of raw pointers and copy constructor.


@OP: The idea of passing (non constant) references is to modify the argument.*
If you want to avoid copies, pass a constant reference, that way works with temporaries too.

*Some like to use pointers in that case, as it makes clear in the calling code that the parameter will be altered.
Topic archived. No new replies allowed.
Pages: 12