For kicks and giggles...

...try making a copy-constructor private, especially if the default copy-constructor is currently being used

I have found that in large, complicated pieces of code, doing so often reveals lots of inefficiencies in code

for instance:

1. returning by reference, but assigning to values unnecessarily
2. passing objects by value instead of by const-reference
3. excessive STL copy-construction

sometimes, automatically generated code can lead to allow for sloppiness
Last edited on
I don't see how that it can reveal inefficiencies? how?
Copy constructor is private, so it can't be used (except by friends and members, of course), so compiler complains about every copy you make, so you get to see them and judge whether they are needed (as they are easy not to notice), so you fix some of them.
hamsterman is 100% correct

it's hard to see this unless you have a large/complex project you can play with

I am almost tempted to start off all new classes with a private copy-constructor, until a public one is really warranted

edit: for example, it's impossible to do a vector< MyClass > without calling copy-constructors - it's obvious when we talk about it specifically now, but when it's imbedded in a large project, it's easy to overlook this fact
Last edited on
Topic archived. No new replies allowed.