Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actuallride

Posted 08 December 2012 - 05:50 PM

Since we are on the subject, why create a vector of pointers in the first place?

Because I want to store different kinds of object in the same vector. This can only be done by storing the pointers or references to the object and using polymorphism.
Also, I store pointers to objects in a vector when the object is too expensive to copy. (When you use std::vector::push_back(), the copy of the object gets stored.)
However, this extra copy can be avoided by using c++11 'move', .


Both of those statements are inaccurate.
If you change it to a list then you wont get assert about the vector because it isn't a vector any more. A std::list does not use code from within the std::vector. You're probably just getting the same error from a different piece of the std library. Getting the same behviour probably means that you are going past the end of the container rather than corrupting it.
If code with vector still compiles, then something else you are including is pulling in the vector header for you. You should probably not be relying on that.

If you need your vector to hold pointers for reasons of polymorphism, then you might be better off with a boost ptr_container rather than a vector. Otherwise you should problably just store instances directly rather than pointers.


This is the only place I'm using vector in my entire project. and I've searched #include <vector> in my entire solution and there was none.
But now that I already solved the problem, what is the advantage of using a boost ptr vector instead of using a normal vector

#3lride

Posted 08 December 2012 - 05:45 PM

Since we are on the subject, why create a vector of pointers in the first place?

Because I want to store different kinds of object in the same vector. This can only be done by storing the pointers or references to the object and using polymorphism.
Also, I store pointers to objects in a vector when the object is too expensive to copy. (When you use std::vector::push_back(), the copy of the object gets stored.)
However, this extra copy can be avoided by using c++11 'move', .


Both of those statements are inaccurate.
If you change it to a list then you wont get assert about the vector because it isn't a vector any more. A std::list does not use code from within the std::vector. You're probably just getting the same error from a different piece of the std library. Getting the same behviour probably means that you are going past the end of the container rather than corrupting it.
If code with vector still compiles, then something else you are including is pulling in the vector header for you. You should probably not be relying on that.

If you need your vector to hold pointers for reasons of polymorphism, then you might be better off with a boost ptr_container rather than a vector. Otherwise you should problably just store instances directly rather than pointers.


This is the only place I'm using vector in my entire project. and I've searched #include <vector> in my entire solution and there was none.
But that I already solved the problem, what is the advantage of using a boost ptr vector instead of using a normal vector

#2lride

Posted 08 December 2012 - 05:43 PM

Since we are on the subject, why create a vector of pointers in the first place?

Because I want to store different kinds of object in a same vector. This can only be done by storing the pointers or references to the object and using polymorphism.
Also, I store pointers to objects when the object is too expensive to copy. (When you use std::vector::push_back(), the copy of the object gets stored.)
However, this extra copy can be avoided by using c++11 'move', .


Both of those statements are inaccurate.
If you change it to a list then you wont get assert about the vector because it isn't a vector any more. A std::list does not use code from within the std::vector. You're probably just getting the same error from a different piece of the std library. Getting the same behviour probably means that you are going past the end of the container rather than corrupting it.
If code with vector still compiles, then something else you are including is pulling in the vector header for you. You should probably not be relying on that.

If you need your vector to hold pointers for reasons of polymorphism, then you might be better off with a boost ptr_container rather than a vector. Otherwise you should problably just store instances directly rather than pointers.


This is the only place I'm using vector in my entire project. and I've searched #include <vector> in my entire solution and there was none.
But that I already solved the problem, what is the advantage of using a boost ptr vector instead of using a normal vector

#1lride

Posted 08 December 2012 - 05:30 PM

Both of those statements are inaccurate.
If you change it to a list then you wont get assert about the vector because it isn't a vector any more. A std::list does not use code from within the std::vector. You're probably just getting the same error from a different piece of the std library. Getting the same behviour probably means that you are going past the end of the container rather than corrupting it.
If code with vector still compiles, then something else you are including is pulling in the vector header for you. You should probably not be relying on that.

If you need your vector to hold pointers for reasons of polymorphism, then you might be better off with a boost ptr_container rather than a vector. Otherwise you should problably just store instances directly rather than pointers.


This is the only place I'm using vector in my entire project. and I've searched #include <vector> in my entire solution and there was none.
But that I already solved the problem, what is the advantage of using a boost ptr vector instead of using a normal vector

PARTNERS