The following code: #include <iostream> #include <vector> #include <cstddef>
struct SomeClass { typedef std::vector<int> TypeVector; TypeVector vec; enum { VectorSize= 10 }; public: SomeClass(); SomeClass(const SomeClass &); }; SomeClass::SomeClass():vec(VectorSize) { using namespace std; for(TypeVector::size_type i= 0; i< vec.size(); ++i) { vec[i]= i; cout<<vec[i]<<" "; } cout<<"\n\n"; } SomeClass::SomeClass(const SomeClass &arg):vec(arg.vec) {} int main() { using namespace std; const size_t SIZE=10; typedef vector<SomeClass> Vector; cout<< "\nCreating vector with "<< SIZE<< " SomeClass objects..."<< endl; Vector vec(SIZE); } produces 10 ints instead of 100: [EMAIL PROTECTED]:~/Projects/Other/anjuta1/src$ ./foobar_cpp Creating vector with 10 SomeClass objects... 0 1 2 3 4 5 6 7 8 9 [EMAIL PROTECTED]:~/Projects/Other/anjuta1/src$ Furthermore, if the copy constructor is not defined explicitly, the program compiles and produces the same output. -- Summary: Copy constructors do not work with std::vector as they should Product: gcc Version: 4.2.3 Status: UNCONFIRMED Severity: blocker Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ivranos at freemail dot gr GCC host triplet: Ubuntu 8.04 x86 GCC target triplet: Ubuntu 8.04 x86 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37720