Ivan Novick wrote:
John Salmon wrote:
>[..]
[..] Here is simplified code. When you run
it, the copy constructor never prints out, indicating it is never
called, but when you make the copy constructor private, the code
doesn't compile. Any one else out there know why g++ is complaining
about a private copy constructor even when it appears never to call
it?
The short answer is "because C++ Standard requires so". Any compiler
that wants to be considered compliant would do that, g++ included.
Not calling an available copy constructor is called optimisation which
may or may not occur (and is also explicitly allowed in the Standard).
However, the initialisation syntax in the original message is called
copy-initialisation, and it requires an *accessible* copy constructor.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask