a question about switch()

J

jalqadir

In my program I have the following statements

void Person::setTitle(const Glib::ustring& str) {
switch ( str ) {
case "None" : {
title = title_t::None;
break;
}
case "Dr" : {
title = title_t::Dr;
break;
}
.......
case "Rabbi" :{
title = title_t::Rabbi;
break;
}
case "Shaykh" :{
title = title_t::Shaykh;
break;
}
default : {
title = title_t::None;
break;
}
}// switch
}//Method

when compiling I get an error code that reads:
==== error: switch quantity not an integer ====
Which is true, but according to

http://newdata.box.sk/bx/c/htm/ch07.htm#Heading54

the error is unwarranted, since the parameter received by the method
and later on given to the switch statement for scrutiny is a valid C/C+
+ statement [setTitle(const Glib::ustring& str)]

Can anyone shed some light to this problem?
 
M

Marco Manfredini

(e-mail address removed) wrote:

[switching over string]
when compiling I get an error code that reads:
==== error: switch quantity not an integer ====
Which is true, but according to

http://newdata.box.sk/bx/c/htm/ch07.htm#Heading54

the error is unwarranted, since the parameter received by the method
and later on given to the switch statement for scrutiny is a valid
C/C+ + statement [setTitle(const Glib::ustring& str)]

Can anyone shed some light to this problem?

Your aforementioned source is distributing misleading informations. The
condition expression over the switch statement has to be of integral or
enumeration type or a class type with a single conversion to an
integral or enumeration type and the label expressions have to be
integral constant expressions. No character literals, structs, doubles
or the alike.
 
J

James Kanze

(e-mail address removed) wrote:
[switching over string]
when compiling I get an error code that reads:
==== error: switch quantity not an integer ====
Which is true, but according to
http://newdata.box.sk/bx/c/htm/ch07.htm#Heading54
the error is unwarranted, since the parameter received by the method
and later on given to the switch statement for scrutiny is a valid
C/C+ + statement [setTitle(const Glib::ustring& str)]
Can anyone shed some light to this problem?
Your aforementioned source is distributing misleading informations.

That's putting it mildly. It's full of a lot of partial
information, and very, very dated. To be avoided.
 

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

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,490
Latest member
Finplus

Latest Threads

Top