Topic: Are these valid using declarations?


Author: Brian Michael Freyburger <freyburg@gamut.stanford.edu>
Date: 1996/10/02
Raw View

I don't think any of the following using declararions are allowed,
because they are not member declarations, but they refer the members
of a class (but I might be wrong).  However, all three seem useful.

class A
{
  typedef int a_type;
  static a_type a;

  static a_type fun(a_type);
};

int foo()
{
  using A::a_type;
  using A::a;
  using A::fun;

  a_type var = fun(a);

  // ...
}

It the case of a static member, or a type member (which, in effect, is
static -- i.e. not associated with any instance of a class).  The
using declaration for a member type *could* be replaced by a typedef,
but it seems that a type at class scope should be treated equivalently
to a type at namespace scope (which can be used in a using
declaration).

A similar argument applies for a static member function -- it should
be treated the same as a namespace scope member function, as far as a
using declaration is concerned.  As far I as can tell, their is now
way to add a static member function's name to your scope otherwise,
and you are required to refer to the fully qualified name.  Maybe this
is a good thing, because static member function where put in the class
for a reason, and maybe you should have to remember the class it came
from every time you use it, but IMHO it should be fine to refer to it
directly (after a using declaration).

Finally, static data member are really similar to static member
functions is this regard, so I think the same issue applies.  [They
are congruent to namespace scope variables.]

However, there might be some accessibility issues.  You don't want to
allow the accessibility of a member of a class to be "leaked" out by a
using declaration.  However, I don't think this can happen, as long as
only functions which have access to the member can have the using
declaration.  Therefore, any protected or private members can only be
added to the scope of friend function's scope, which have no way of
"giving" it to other entities.


Brian Freyburger


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]