Hello, [EMAIL PROTECTED] wrote:
> 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 None of the examples there uses anything different from int. You'd better use a textbook on the language to read on the restrictions of switch, not some bogus information in a document focuses on some library. The error is perfectly ok, so this is not a gcc problem. You could use some map to map the strings to values to avoid the if..else if...else if cascade. Maybe like the following. typedef std::map<Glib::ustring&, title_type> strToTitleType; strToTitleType strToTitle; ... ...initStrToTitle() { strToTitle["None"] = title_t::None; ... strToTitle["Shayk"] = title_t::Shayk; } .... void Person::setTitle(const Glib::ustring& str) { strToTitleType::const_iterator sit = strToTitle.find(str); if (sit == strToTitle.end()) title = title_t::None; else title = sit->second; } Bernd Strieder _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus