|
-
August 15th, 2011, 12:57 PM
#15
Re: Why would vector::size() give a garbage value ?
 Originally Posted by kmkkra
I updated my program for you, and stripped it down as you've said. You were right it could be stripped down even further. I also narrowed down what the problem is - which I noted in my last post next to the file up for review.
To add to what Lindley stated, if you really wanted CApplicationView to turn off copying, you did not do it correctly.
1) The copy constructor should be private, which you did do, but it should also be unimplemented, meaning it should not have a function body. Your version has an empty function body, which is not good enough -- it should have no function body at all.
This is the corrected code:
Code:
CApplicationView(CApplicationView&); // note -- no function body, not
// even an empty one!
The reason is that if you have any function body whatsoever, you can still make copies within the CApplicationView class itself, and copying is what you're trying to avoid. Making the function unimplemented completely turns off the copying mechanism, both at compile and link time.
2) You did not overload an operator= to turn off assignment. It should be done the same way as the copy constructor -- private and unimplemented.
Regards,
Paul McKenzie
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
|