Re: about constructor and switch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux