Michael Gerz <[EMAIL PROTECTED]> writes:

| Angus Leeming wrote:
| 
| >Michael Gerz <[EMAIL PROTECTED]> writes:
| >
| >> After having introduced the enum in the last two hours, I finally
| >> come to the conclusion that a simple bool type is more suitable
| >> than an enum type for which C++ does not provide any type-safety.
| >> There are just two values, on and off. That's what bool is made for
| >>
| >
| >That's not true. The enum is perfectly type safe and is self-documenting,
| >something the enum isn't. Indeed, I'm pretty sure that one of those C++ gurus
| >(Meyers, Sutter, etc) recommends the use of enum over bool...
| >
| No, enum is NOT type-safe. I started with something like
| 
|    enum Tracking {
|      on,
|      off
|    }

You should at least have used:

    enum Tracking {
      off,
      on
    }


| just to discover that a statement like
| 
|   if (tracking_changes) {
|     ..
|   }

Enums are type-safe, but also convertible to an integer type.
(but not from integer to enum)

-- 
        Lgb

Reply via email to