简体   繁体   中英

standard library STL in c++

Can someone explain the below code?

vector<int> *vpoint =  new vector();

from what little i know, vector vpoint creates a vecor of type int, vpoint being its name. Then why do we need the above type of code?

And do we use the arrow operator -> with the the former code and use the dot operator with the latter code. Am i right. can someone explain in detail.

Is this something got to do with pointers?

Any help is appreciated. Thanks

First of all, you'r original code will not compile. However, answering your question, code (with fixed compilation error):

vector<int>* vpoint = new vector<int>;

Simply creates an object of std::vector class on the heap, and assigns an address of this object to vpoint variable.

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