|
-
April 27th, 2009, 10:47 AM
#7
Re: class constructor question
 Originally Posted by StGuru
There is copy created of the ob2. I should use pass by reference if I alter the ob1 variables but I don't alter them.
For example if I need to change something in the object
Function1(test &ob1)
{
ob1.z=5;
}
or something like that.
You're missing the ****ing point.
When you pass T by-value, T's copy constructor gets invoked. In your case, over and over and over. In short, impossible. Passing T by (const) reference alleviates that problem.
If you don't understand this simple concept, perhaps you should stick with shallow copying for now. Besides, that snippet in your OP doesn't require an explicit copy constructor in the first place.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|