vector<pair..> >::iterator

G

Gary Wessle

Hi
is it ok to do this? if not, then how

for (vector<pair<char,double> >::const_iterator it = v.begin(); it != v.end(); ++it)
switch (*it->first){...

thanks
 
V

Victor Bazarov

Gary said:
is it ok to do this? if not, then how

for (vector<pair<char,double> >::const_iterator it = v.begin(); it
!= v.end(); ++it) switch (*it->first){...

'it->first' is a char. You cannot dereference a char. You have one
too many indirections. Either use

switch (it->first) {

or

switch ((*it).first) {

Which should be the same AFA C++ is concerned.

V
 
M

mlimber

Gary said:
is it ok to do this? if not, then how

for (vector<pair<char,double> >::const_iterator it = v.begin(); it != v.end(); ++it)
switch (*it->first){...

No. Did you even try it? The element "first" is not a pointer, so you
can't dereference it. Drop the star *or* parenthesize (*it) and change
the arrow to a dot, and then it will compile.

Cheers! --M
 
G

Gary Wessle

Gary Wessle said:
Hi
is it ok to do this? if not, then how

for (vector<pair<char,double> >::const_iterator it = v.begin(); it != v.end(); ++it)
switch (*it->first){...

never mind, I found it after some trial and error

switch( (*it).first )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top