Topic: Locality of structure tag names


Author: brucec@phoebus.phoebus.labs.tek.com (Bruce Cohen;;50-662;LP=A;)
Date: 20 Aug 90 21:47:02 GMT
Raw View
I'd like to get a clarification of the locality of scope of a structure tag
name declared inside a class.

According to Ellis&Stroustrup, a typename declared in a class declaration
is local to that class, and (modulo C compatibility issues) all types,
including structure tags, share a namespace.  My reading of this is that
structure tags declared inside a class definition are local to the class
(and that's the way I'd like it to be).  Am I assuming too much?

My Cfront 2.0 makes class-nested typedefs and structure tags
global (at file scope, that is), which is about what I expected.

Example:

class Nest
{
  public:
    Nest(int);

  private:
    struct nested
    {
        int egg;
    };
    typedef struct nested nestedType;
};

Nest::Nest(int i)
{
    struct nested* nesting = new struct nested [i];   // within scope
}

void Tree(struct nested* nesting)    // illegal: out of scope
{
    // mumble ...
}

void Shrub(nestedType* nesting)    // illegal: out of scope
{
    // mumble ...
}

--
---------------------------------------------------------------------------
NOTE: USE THIS ADDRESS TO REPLY, REPLY-TO IN HEADER MAY BE BROKEN!
Bruce Cohen, Computer Research Lab        email: brucec@tekcrl.labs.tek.com
Tektronix Laboratories, Tektronix, Inc.                phone: (503)627-5241
M/S 50-662, P.O. Box 500, Beaverton, OR  97077