From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Gordon Neal" To: Subject: STL Question not answered in FAQ Date: Wed, 31 Mar 1999 23:46:00 -0000 Message-ID: <001b01be7237$e0298de0$5acb6689@pdxnw392.pdx.intel.com> X-SW-Source: 1999-03n/msg00667.html Message-ID: <19990331234600.sNegphPNfDrblUOG7dHUHEVtHjYaNBOOJUkbAzx8Vbk@z> I am trying to use STL in the latest egcs release and have encountered a problem that seems fairly simple but I have yest to figure out why my code doesn't work. Here is an example of the code: #include #include "stl.h" class PtrWrapper { int *a; public: PtrWrapper() {} PtrWrapper(int *x):a(x) {} ~PtrWrapper() {} PtrWrapper(const PtrWrapper& x) {} PtrWrapper& operator= (const PtrWrapper& x) { } }; class B { friend class D; list ptr; public: B() {} ~B() {} B(const B& x) {} B& operator= (const B& x) { } addPtr(int *a) { ptr.push_back(PtrWrapper(a)); } }; class C { friend class D; vector listb; public: C() {} C(int size) { int i; listb.reserve(size); printf("Reserved %d for list B\n",size); for (i = 0; i < size; i++) { listb.push_back(B()); } } ~C() {} C(const C& x) {} C& operator= (const C& x) { } }; class D { vector listc; int i; int j; public: D() {} D(int sizec, int sizeb) { int i; listc.reserve(sizec); for (i = 0; i < sizec; i++) { listc.push_back(C(sizeb)); } } ~D() { } D(const D& x) {} D& operator= (const D& x) { } print() { int k = 0, l = 0; vector::iterator i; vector::iterator j; printf("The size of vector c is %d\n",listc.size()); for (i = listc.begin(); i != listc.end(); i++) { printf("The size of vector b for listc[%d] is %d\n",k++,i->listb.size()); for (j = i->listb.begin(); j != i->listb.end() ; j++) { printf("j = %d\n",l++); } } } }; main(int argc, char**argv) { D d(10,20); d.print(); } The output of this: Reserved 20 for list B Reserved 20 for list B Reserved 20 for list B Reserved 20 for list B Reserved 20 for list B Reserved 20 for list B Reserved 20 for list B Reserved 20 for list B Reserved 20 for list B Reserved 20 for list B The size of vector c is 10 The size of vector b for listc[0] is 0 The size of vector b for listc[1] is 0 The size of vector b for listc[2] is 0 The size of vector b for listc[3] is 0 The size of vector b for listc[4] is 0 The size of vector b for listc[5] is 0 The size of vector b for listc[6] is 0 The size of vector b for listc[7] is 0 The size of vector b for listc[8] is 0 The size of vector b for listc[9] is 0 The question is why is listb size 0? What am I doing wrong? Thanks