Re: being copy constructible
Ivan Novick wrote:
James Kanze wrote:
The real problem is that he cannot copy const objects.
Ok, but then would you agree that you can have a non-const copy
constructor and use said objects in any STL container as long as he
does not try use any const objects in which case he would get a
compiler error?
No. The implementation of the STL container has the right to
use const instances of the object type, and to copy them. The
following simple program fails to compile with g++ when all of
the usual debug options are set:
#include <vector>
struct C
{
C() {}
C( C& ) {}
} ;
int
main()
{
std::vector< C > v ;
return 0 ;
}
You'll note that I have no const objects anywhere myself.
By definition, if you cannot copy a const object, the type is
not CopyConstructable, and if it isn't CopyConstructable, it is
undefined behavior to use it to instantiate a standard
container.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]