Re: a c++ question
On Thu, Jul 15, 1999 at 07:50:45AM -0300, Ivan J. Varzinczak wrote:
: 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.
object1 is storage class `auto' ... it's {con,de}structed for
each iteration. (You may insert cerr<< - statements in the
{con,de}structor methods.
Since it's _automatic_ you can't use the reference or a pointer
to that object outside your loop! Some compilers issue a warning if you
do so.
It depends on the implementation of `insert(object1)' if it works.
Normally (?) insert(object1) should make a own copy of the object to be
inserted, since it can't guess anything about the storage class
of the object to be inserted.
Best Regards from Dresden / Germany,
Viele Gruesse aus Dresden,
Heiko Schlittermann
--
[internet & unix support ----------------- Heiko Schlittermann]
[<a href="http://debian.schlittermann.de/"> Debian 2.1 CD </a>]
[Heiko Schlittermann HS12-RIPE finger:heiko@schlittermann.de -]
[pgp: A1 7D F6 7B 69 73 48 35 E1 DE 21 A7 A8 9A 77 92 -------]
Reply to: