Dynamically allocated Vector

Hi all,

I have always used this declaration for a member of the vector class:

vector<double> myvec;

Then typically I use reserve() method. My vector is usually large in size.

Now, I know that a member of vector class is actually a c++ dynamically allocated array. So, that's why I never use this declaration:

vector<double>* myvec;

What do you think about this? Would it be any advantage in declaring it as vector<double>* instead of the simpler vector<double>?

Thanks!

closed account (zb0S216C)
aortizb wrote:
"Would it be any advantage in declaring it as vector<double>* instead of the simpler vector<double>?"

No, unless you need to point to a vector. Dynamically allocating a "std::vector" is pointless unless its defined within a structure that needs to be dynamically allocated or if the "vector" needs to be stored within a specific place in memory, in which case "new" is not appropriate.

Wazzak
Last edited on
Topic archived. No new replies allowed.