Boost logo

Boost :

From: Mattias Flodin (flodin_at_[hidden])
Date: 2002-04-16 16:09:36

On Tue, Apr 16, 2002 at 02:42:53PM -0400, Neal D. Becker wrote:
> Why are we not allowed to do:
> class X {
> using foo:whatever;
> ...
> };

Hi Neal,

Spontaneously, it would seem that there are two subtly different variants of
the using-declaration: One that lets you import things from namespaces, and
another that lets you import things from base classes. This probably leads to
some kind of ambiguity in the grammar. I can't really see a reason why it
couldn't be disambiguated by simply making two different productions (i.e.
"using-from-namespace-declaration -> using namespace-id::id" and
"using-from-base-declaration -> using class-id::id").

Curiously, as far as I can tell the standard doesn't mention this kind of
combination. It does mention that you can't do the opposite: trying a
using-declaration on a class member in a scope that is not part of a class
(; something that seems rather odd to try or even think of doing.

However, I can imagine that it would become rather problematic in the long
run, because you will have two syntactically identical constructs that have
different semantics depending on how the identifiers you are using were
declared. That is,

using baseclass-name::id;

means "Take baseclass-name::id and declare it within this class as a
member," but

using namespace-name::id;

means "When I refer to id within this class, I really mean
namespace-name::id." To take a more specific example, if you have a class
such as this:

class A : private B {
    using std::sort;
    using B::f;

then A a; a.f(); would be legal, but a.sort(...); would not be legal
because sort() is not a member function of A (which, on the other hand, f()
is because of the using-declaration).

I hope that's at least a partial explanation... but yes it would be nice if
the standard covered this a little more thoroughly.


Mattias Flodin <flodin_at_[hidden]>  -
Room NADV 102
Department of Computing Science
Umeå University
S-901 87 Umeå, Sweden
If you were a gladiator in olden days, I bet the inefficiency of how the
gladiator fights were organized and scheduled would just drive you up a
  -- Jack Handy

Boost list run by bdawes at, gregod at, cpdaniel at, john at