[comp.lang.c++] Nested Types

sdm@cs.brown.edu (Scott Meyers) (06/18/91)

According to ARM section 7.2 (p. 115), "Enumerators defined in a class are
in the scope of that class and can be referred to outside member functions
of that class only by explicit qualification with the class name."  An
example is given:

    class X {
    public:
      enum direction { left = 'l', right = 'r' };
      int f(int i);
    };

    direction d;     // error:  'direction' not in scope

    X* p = new X;
    p->f(left);      // error: 'left' not in scope
    p->f(X::right);  // ok

This I understand.  However, in The Fall 1990 issue of the C++ Journal,
Stan Lippman writes an article, "Nested Types in C++," in which he offers
this example on p. 32:

    class ZooAnimal {
    public:
      enum ZooArea { TBD, Cats, Apes, Elephants };
      ...
    };

    ZooArea myArea = Elephants;             // error

    ZooAnimal::ZooArea myArea = Elephants;  // ok

Is this correct?  I would expect that Elephants has to be explicitly
qualified as being in the ZooAnimal class:

    ZooAnimal::ZooArea myArea = ZooAnimal::Elephants;

Is there a mistake in Lippman's article, was there a change in the rules
since publication of the ARM, or am I missing something?

Thanks,

Scott
sdm@cs.brown.edu

-------------------------------------------------------------------------------
What do you say to a convicted felon in Providence?  "Hello, Mr. Mayor."