Topic: Things left unstated by the draft
Author: daniel@cse.ucsc.edu (Daniel R. Edelson)
Date: 2 Mar 1993 02:41:19 GMT Raw View
I'd like to know if anyone can definitively state that the following
are legal or illegal. All responses are appreciated.
1) Does a static member initializer have the same accessibility
as a member function? Scope yes, accessibility? (Probably the
answer should be yes, but I couldn't find an explicit mention.)
struct base {
protected:
static int x;
};
int base::x = 0;
struct derived : public base {
static int y;
};
int derived::y = base::x; // Same saccessibility as member func?
This is probably legal but I couldn't find a sentence in the
draft that permits it.
2) Definition of accessibility: Is a protected base class accessible?
It's public members are accessible, but only for an object's
own subobject.
struct base { };
struct d1 : protected base { };
struct d2 : protected base { base * f(d1 *); };
base * d2::f(d1 * p) { return p; } // Legal
That's all for the moment. All comments are appreciated. Thanks.
Daniel Edelson
daniel@cse.ucsc.edu
Author: pcwu@csie.nctu.edu.tw ()
Date: Tue, 9 Mar 1993 09:34:04 GMT Raw View
Daniel R. Edelson (daniel@cse.ucsc.edu) wrote:
: I'd like to know if anyone can definitively state that the following
: are legal or illegal. All responses are appreciated.
:
: 1) Does a static member initializer have the same accessibility
: as a member function? Scope yes, accessibility? (Probably the
: answer should be yes, but I couldn't find an explicit mention.)
Yes. See pp.180 of ARM:
"Static members obey the usual class member access rules except that
they can be initialized (in file scope)."
This definition is quite clear; however, I found that g++ cannot allow
a private static data member be initialized in file scope. Look at the example
on pp.180, it initializes some private static data members.
: 2) Definition of accessibility: Is a protected base class accessible?
: It's public members are accessible, but only for an object's
: own subobject.
:
: struct base { };
: struct d1 : protected base { };
Protected base class is not defined in ARM. I think it should be
illegal, although the grammar in ARM appendix allows such syntax.
Regards,
----------
Pei-Chi Wu
Institute of C.S.I.E.
Nat'l Chiao-Tung Univ.
Hsinchu, Taiwan 30050
e-mail: pcwu@csie.nctu.edu.tw
-----------------------------