[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

a c++ question



Hi folks! 

   I'm willing to declare an object inside a while loop and
do something with it, like this:

   ... 

   while(condition){

      ClassOfTheObject object1;

      ... 

      insert object1 in a list, for example;

      ... 

   }

   ... 

   The most impressionant is that in the second time the code 
of the loop is executed, object1 references the same object, so
the changes in atributes of the object1 of the first execution
are lost and all that is made with the object of the second ite-
ration overwrites the first iteration one. After this, I have
two objects exactly equal. In the same way, if the loop is exe-
cuted n times, I'll get n equal objects. 
   Have I to dealocate this object at the end of the loop? C++
doesn't destroy it by default and create a new one every time
entering in the while loop? 
   May someone tell me any suggestions about this? I'm using
g++ egcs-2.91.60. 

   Thanks in advance.

-- 
Ivan J. Varzinczak - (mailto: ivan@inf.ufpr.br)
Bolsista PET/CAPES - Depto. de Informatica - UFPR
Curitiba - Parana - Brasil
Phone: +55 (041) 347-3240 - 267-5244 r.315

15-VII-1999


Reply to: