Reputation: 1516
typedef map<char,string> someMap;
someMap *mapPtr=someClass.getMap();
*(mapPtr)["a"].length();
The last line of this code fails. What should I to in order to make this work?
Upvotes: 2
Views: 105
Reputation: 10780
(*mapPtr)['a'].length();
the *
operator has a lower precedence than []
so you have to but that in brackets. Also "a"
is the string literal (char array) whereas you want 'a'
A complete list of operator precedences in C++ can be found here
Upvotes: 3
Reputation: 53097
[]
has higher precedence than *
This is likely what you intend:
(*mapPtr)["a"].length();
Upvotes: 1