Topic: Bug with Vector???
Author: "X. Liu" <liu@erdw.ethz.ch>
Date: 1998/09/17 Raw View
use vector<Object *> if you want to put pointer to the vector.
-------Xingzeng
Nathan Zhang wrote in message <35FD5F94.1376D2D1@iprint.com>...
>
> I'm using VC++ 5.0 on Win98. I'm tring to implement a vector of user
>defined obejects.
[ moderator's note: excessive quoting deleted. Please limit
quoting to only what is necessary. -sdc ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Edward Diener <eddielee@abraxis.com>
Date: 1998/09/15 Raw View
If obj1 ( and obj2 and obj3 ) are all created with "new" your vector should
be:
vector <Object *> _object;
and its then your responsibility to delete the objects in the vector through
their object pointers.
Nathan Zhang wrote:
> Hi all,
> I'm using VC++ 5.0 on Win98. I'm tring to implement a vector of user
> defined obejects.
> class Object
> { ...........
> ...........
> ...........
> };
> vector <Object> _object;
> _object.push_back(obj1); //obj1, 2, 3 are all Objects created from
> "new"
> _object.push_back(obj2);
> _object.push_back(obj3);
> after this, obj2 or _object[1] got trashed for some reason. Did
> anyone have the similar problem? How can I go around this.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Thomas T. Veldhouse" <veldy@visi.com>
Date: 1998/09/15 Raw View
Could you give us more information? What is relavent you ask? How about
whether we have a copy constructor on Object, and perhaps whether there is
an assignment operator. Are the objects you are pushing into the vector
pointers? You said they were created with "new".
Tom Veldhouse
Nathan Zhang wrote in message <35FD5F94.1376D2D1@iprint.com>...
>
>Hi all,
> I'm using VC++ 5.0 on Win98. I'm tring to implement a vector of user
>defined obejects.
>
>class Object
>{ ...........
> ...........
> ...........
>};
>
>vector <Object> _object;
>_object.push_back(obj1); //obj1, 2, 3 are all Objects created from
>"new"
>_object.push_back(obj2);
>_object.push_back(obj3);
>
>after this, obj2 or _object[1] got trashed for some reason. Did
>anyone have the similar problem? How can I go around this.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Nathan Zhang <nzhang@iprint.com>
Date: 1998/09/14 Raw View
Hi all,
I'm using VC++ 5.0 on Win98. I'm tring to implement a vector of user
defined obejects.
class Object
{ ...........
...........
...........
};
vector <Object> _object;
_object.push_back(obj1); //obj1, 2, 3 are all Objects created from
"new"
_object.push_back(obj2);
_object.push_back(obj3);
after this, obj2 or _object[1] got trashed for some reason. Did
anyone have the similar problem? How can I go around this.
Thanks.
Nathan
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]