about constructor and switch
Eljay Love-Jensen
eljay@adobe.com
Thu Sep 9 11:54:00 GMT 2004
Hi,
The switch C/C++ construct can only take an integer.
It cannot take an object (unless that object is convertible to an
integer). Thus, it cannot take a std::string.
It cannot take a float, double, long double. Or a complex. Or a pointer.
It can take a char, short, int, long or bool, or any expression which
evaluates to such.
Some languages, such as Ada, have a more capable switch construct, which
can handle those other situations that C/C++ cannot.
For those more complicated situations in C/C++, use a if/else if/else
construct, or use polymorphism (where applicable).
HTH,
--Eljay
More information about the Gcc-help
mailing list