I have the following code:
map<StatTypesEnum, ValueHandler*>::const_iterator itr;
for(itr=player1->Stats.begin(); itr!=player1->Stats.end(); itr++)
{
cout << "Stat: " << itr->first << " Value: " << (ValueHandler*)(itr->second)->getValue() << endl;
}
The getValue() method returns an int. If I cout the value outside of the iterator, it displays in base10 decimal, however when i return the value using an iterator (as above) it displays in base16, hex.
Just for completeness, the following line displays as base10:
cout << player1->Stats[Power]->getValue() << endl;
I would like the iterator to display base10.
Thanks.
When you print
(ValueHandler*)(itr->second)->getValue()you should be getting a hexadecimal value because that’s how pointers are printed. You probably shouldn’t be casting the return value ofgetValue()to aValueHandler*. You probably intended to castitr->secondto that pointer type (although it’s not necessary) but just got the parentheses wrong. Here’s what castingitr->secondwould look like:And what you want is probably: