简体   繁体   中英

Vector of pointer declaration

Looking at some code my professor gave me and I don't understand what is happening. I am new to programming and completely lost.

vector <_Account*>*myvector = nullptr;

So I know he made a vector, and I know of an existing class called Account so is this a vector of pointers to an Account objects? and I don't know what the second asterisk does?

myvector is a pointer to vector (most likely std::vector + the bad practice using namespace std; ) of pointers to _Account . No actual vector is created in this line, just a variable that can store the address of one.

_Account is an implementation reserved identifier btw, it must not be used.

This is a pointer to a vector of pointers to _Account (very badly named) class. To use the vector, it should either be allocated, or assigned to address of already existing vector of the same type. To use it's _Account elements, those elements in turn needs to be either allocated, or assigned to the addresses of existing _Account instances.

Lets break it down into two steps:

typedef vector<_Account*> objectvector;

objectvector *myvector = nullptr;

1) objectvector is a vector of pointers(of type _Account).

2) myvector is a pointer to type objectvector.

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