Topic: How to declare namespacemembers?
Author: schuenem@informatik.tu-muenchen.de (Ulf Schuenemann)
Date: 1995/06/12 Raw View
In article <JASON.95Jun8150837@phydeaux.cygnus.com>, jason@cygnus.com (Jason Merrill) writes:
[..]
|> > // file.h
|> > namespace X {
|> > namespace p {
|> > extern int q; // declares X::q, not p::q !
|> > extern int f (); // declares X::f, not p::f !
|> > }
|>
|> Why must it? Within p, p is the innermost enclosing namespace.
This, of course, is true. I must have been blind. Everything is alright
now. Thank you for opening my eyes.
Ulf Schuenemann
--------------------------------------------------------------------
Ulf Sch nemann
Fakult t f r Informatik, Technische Universit t M nchen, Germany.
email: schuenem@informatik.tu-muenchen.de
Author: schuenem@informatik.tu-muenchen.de (Ulf Schuenemann)
Date: 1995/06/08 Raw View
How can I declare a namespace-member ?
7.3.1.4 Namespace member definitions [namespace.memdef] 4 says:
> When an entity declared with the extern specifier is not found to refer
> to some other declarartion, then that entity is a member of the innermost
> enclosing namespace.
It goes on to give an example with "extern" within the body of a namespace-
memberfunction. As the "When an entity declared with the extern specifier"
is not restricted to functionbodies, this rule must also apply to
namespace-membernamespace:
// file.h
namespace X {
namespace p {
extern int q; // declares X::q, not p::q !
extern int f (); // declares X::f, not p::f !
}
int f (); // declares X::f
}
// file.C
#include "file.h"
int X::f ()
{ return p::q; } // error: q not yet declared !
int X::p::f () // error: f is not a member of p !
{ return q; } // referes to X::q !
I find this situation very unpleasent.
I can't believe that it was the intent of the committee to
prohibit the possibility of declaring variables as namespacemembers.
-> Please tell me, if I misunderstood or missed something. <-
It would be a shame, if namespaces where mainly designed for
functions (that dont need the keyword "extern" to form a declaration)
but not also for variables.
HOW CAN I _DECLARE_ A NAMESPACE-MEMBERVARIABLE ???
IMHO the wording should be changed to something like:
> Within a scope that is not a namespace, when an entity declared with
> the extern specifier ...
Ulf Schuenemann
--------------------------------------------------------------------
Ulf Sch nemann
Fakult t f r Informatik, Technische Universit t M nchen, Germany.
email: schuenem@informatik.tu-muenchen.de
Author: jason@cygnus.com (Jason Merrill)
Date: 1995/06/08 Raw View
>>>>> Ulf Schuenemann <schuenem@informatik.tu-muenchen.de> writes:
> How can I declare a namespace-member ?
> 7.3.1.4 Namespace member definitions [namespace.memdef] 4 says:
>> When an entity declared with the extern specifier is not found to refer
>> to some other declarartion, then that entity is a member of the innermost
>> enclosing namespace.
> It goes on to give an example with "extern" within the body of a namespace-
> memberfunction. As the "When an entity declared with the extern specifier"
> is not restricted to functionbodies, this rule must also apply to
> namespace-membernamespace:
> // file.h
> namespace X {
> namespace p {
> extern int q; // declares X::q, not p::q !
> extern int f (); // declares X::f, not p::f !
> }
Why must it? Within p, p is the innermost enclosing namespace.
Jason