I’m working on a program and have a strange, cout related problem. Since the program is a bit big and the code talks best, I’ll paste the relevant snippets.
First, I have an iterator, *it defined in a for as
for(vector<facet*>::iterator it=facets_to_dump->begin(); it<facets_to_dump->end(); it++)
In this for, if I use the expression
facet* facet_to_work_on = *it;
cout << facet_to_work_on->facet_id << "\t";
Nicely prints out integers.
But, if I use the notation
cout << (facet*)(*it)->facet_id << "\t";
This code prints out hex values. Hex values are equal to the integer values. Any idea why this is happening?
Thanks in advance.
The reason
prints out a hex value is that -> binds harder than the (facet*) cast, that is it evaluates
and casts the result to a facet*. Pointers are output in hex.