smttsp
smttsp

Reputation: 4191

complex vector pointer

vector <unordered_map <string, DomainInfo *> *> victimDomains;

What does this mean?

I got the first star (DomainInfo*) but what is the second one?

Lets say DomainInfo has two properties ID and name. If I want to bring the second element in DomainInfo of third unordered_map in victimDomains how could I call it? is my question not correct?

Thanks,

Upvotes: 0

Views: 109

Answers (2)

Karthik T
Karthik T

Reputation: 31952

In plain english, it is a vector of pointers to (unordered_maps mapping strings to pointers of DomainInfo). (using brackets to indicate levels)

You want to do

(*victimDomains[2])[<domainInfoKey>]->name;
 ^B             ^A    ^C                ^D

A - 2nd Element - a pointer to the map.
B - Dereference the pointer to the map to get a map.
C - Get the DomainInfo pointer (need to enter the correct string)
D - Use -> syntax to access the name field from the DomainInfo pointer.


Above in multiple steps -

unordered_map <string, DomainInfo *> *map = victimDomains[2];

DomainInfo *dmInfo = *map[<domainInfoKey>];

Name name = dmInfo->name;

Upvotes: 6

To access a particular DomainInfo, you need to know its key in the unoreder_map. So exactly as it stands, your question (how to access?) cannot be answered. However, if you knew the DomainInfo's key was, let's say, "blah", then you would do:

(*victimDomains[2])["blah"]->name

Upvotes: 1

Related Questions