简体   繁体   中英

Creating an Array of Vector Pointers

I have to input a number "N" and create an array of vector pointers so that by using Polymorphism I am able to place different objects at different indexes of the vector. What I'm trying to do:

vector<Vehicle> *ptr(N);

This gives an error, how can I create an array of vector pointers of type?

The standard C++ doesn't support Variable-Length Array (VLA), so you should create a vector of vector pointors instead.

std::vector<vector<Vehicle> *> ptr(N);

If your compiler supports VLA and you want to use that for some reason, you should use [] instead of () .

vector<Vehicle> *ptr[N];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM