[comp.lang.c++] Scope of return types

keffert@nyssa.cs.orst.edu (Thomas Keffer) (12/28/90)

What is the scope of the *return* value of a definition?
File scope?  or Local scope?

Consider the following:

class A {
public:
  enum Color {black, white};
  static Color x;
};

Color    A::x = black;	// Correct?

A::Color A::x = black;	// How about this?

-Tom Keffer
 Rogue Wave
 keffer%rwave.uucp@cs.orst.edu

glenn@huxley.huxley.bitstream.com (Glenn P. Parker) (12/28/90)

In article <1990Dec27.203259.9391@usenet@scion.CS.ORST.EDU>,
keffert@nyssa.cs.orst.edu (Thomas Keffer) writes:
> Consider the following:
> 
> class A {
> public:
>   enum Color {black, white};
>   static Color x;
> };
> 
> Color    A::x = black;	// Correct?
> 
> A::Color A::x = black;	// How about this?

How about these:

    Color A::x = A::black;	// C++ 2.0 does like this.

    A::Color A::x = A::black;	// C++ 2.1 should like this (?)

My C++ 2.0 compiler (cfront-based) doesn't like "A::Color", but I think a
C++ 2.1 compiler would accept it.

--
Glenn P. Parker       glenn@bitstream.com       Bitstream, Inc.
                      uunet!huxley!glenn        215 First Street
                      BIX: parker               Cambridge, MA 02142-1270

rae@alias.UUCP (Reid Ellis) (01/03/91)

Glenn P. Parker <glenn@huxley.huxley.bitstream.com> and Thomas Keffer
<keffert@nyssa.cs.orst.edu> discuss the following:

>> class A {
>> public:
>>   enum Color {black, white};
>>   static Color x;
>> };

There was some question about how to define the static [class]
variable 'x'.  The proper way to do this is:

>    Color A::x = A::black;	// C++ 2.0 does like this.

A type can never be nested inside another type.  Thus statements like
the following are not legal:

>    A::Color A::x = A::black;	// C++ 2.1 should like this (?)

You can have anonymous types such as:

	struct {
		int a, b;
		void foo() { a++; }
	} var;

Here the type of 'var' is undefined.  You can say var.foo() and even
reference var.a and var.b, but you can't assign it or anything else;
it's a uniquely typed variable.

					Reid
--
Reid Ellis  176 Brookbanks Drive, Toronto ON, M3A 2T5 Canada
rae@gpu.utcs.toronto.edu      ||  rae%alias@csri.toronto.edu
CDA0610@applelink.apple.com   ||             +1 416 446 1644

glenn@huxley.huxley.bitstream.com (Glenn P. Parker) (01/05/91)

In article <rae.662888238@barney> rae@alias.UUCP (Reid Ellis) writes:
> A type can never be nested inside another type.  Thus statements like
> the following are not legal:
> 
>>     A::Color A::x = A::black;	// C++ 2.1 should like this (?)

May I direct your attention to Ellis & Stroustrup: Section 9.7, entitled
"Nested Class Declarations," which implies that such statements are quite
legal, IMHO.  Remember, this is 2.1 we're talking about, not 2.0.

--
Glenn P. Parker       glenn@bitstream.com       Bitstream, Inc.
                      uunet!huxley!glenn        215 First Street
                      BIX: parker               Cambridge, MA 02142-1270