Topic: using for whole class


Author: dak <pierreba@poster.cae.ca>
Date: 1995/12/13
Raw View
I recall a conversation on the using keyword but no mention of an answer to
this: why isn't it possible to use the using keyword to import a whole class
into another ? Or am I mistaken and skipped some part of the standard ?

The use for such a beast would be in templates (or more often in derived
templates). I won't go so far as suggesting a syntax (been burned once)
but the obvious one, mirroring the use with namespace, would seem to do.


[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]






Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/12/13
Raw View
In article 100000@zorglub.cae.ca, dak <pierreba@poster.cae.ca> writes:
>I recall a conversation on the using keyword but no mention of an answer to
>this: why isn't it possible to use the using keyword to import a whole class
>into another ?

What would you want it to mean? For example:

 struct B { int y; };
 struct C {
  using B; // using-declaration
  // or
  using namespace B; // using-directive
 };

Do you want it to mean that the name B is visible in C? It already is.

Do you want it to mean that the names of the members of B can be
used without qualification in member functions of C? That might make
sense for type names or enumerators, but certainly not for non-static
data or function members. (They have to be associated with an object,
not just with a type.)

Do you want it to mean that C has a nested type called B? You can do that
with a typedef:
 struct C {
  typedef ::B B;
 };

Do you want it to mean that C has a member of type B? A using declaration
or directive can't do that; besides, the member needs a name.

If B is a base class of C, the name B and all its members are already
visible in and members of C. The using declaration or directive for
the class would not declare anything that wasn't already the case.
(Except for issues of name hiding, which you would need to resolve on
a name-by-name basis anyway.)
---
Steve Clamage, stephen.clamage@eng.sun.com




---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]





Author: John Max Skaller <maxtal@suphys.physics.su.oz.au>
Date: 1995/12/19
Raw View
clamage@Eng.Sun.COM (Steve Clamage) wrote:
>
>In article 100000@zorglub.cae.ca, dak <pierreba@poster.cae.ca> writes:
>>I recall a conversation on the using keyword but no mention of an answer to
>>this: why isn't it possible to use the using keyword to import a whole class
>>into another ?
>
>What would you want it to mean?

Well, now you ask, I'd like to be able to use an _expression_
in a class -- to implement delegation. For example:

 class W { void g(); };
 class X { void f(); };
 class Y {
   X x;
   W *pw;
   using x;
   using *pw;
 };

 Y y;
 y.f(); // OK, means y.x.f()
 y.g(); // OK, means (*y.pw).g()

--
John Max Skaller               voice: 61-2-566-2189
81 Glebe Point Rd              fax:   61-2-660-0850
GLEBE NSW 2037                 email: maxtal@suphys.physics.oz.au
AUSTRALIA                      email: skaller@maxtal.com.au




---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]





Author: ajay@lehman.com (Ajay Kamdar)
Date: 1995/12/20
Raw View
In article <4b4e2j$752@oznet03.ozemail.com.au>,
John Max Skaller  <maxtal@suphys.physics.su.oz.au> wrote:
>
>Well, now you ask, I'd like to be able to use an _expression_
>in a class -- to implement delegation. For example:
>
> class W { void g(); };
> class X { void f(); };
> class Y {
>   X x;
>   W *pw;
>   using x;
>   using *pw;
> };
>
> Y y;
> y.f(); // OK, means y.x.f()
> y.g(); // OK, means (*y.pw).g()

Yeah right, like we really need to grow the language even more by
providing for new ambiguities:

    struct W {
 void g();
 void f();   // new member function to W
    };
    struct X ....   // similar to above example
    struct Y ....   // similar to above example

    Y y;
    y.f();   // Ambiguity: y.x.f()? Or (*y.pw).f()?

--
Ajay Kamdar        |    Email: ajay@lehman.com    |    Standard Disclaimer
Lehman Brothers    |    Phone: (201) 524-5048     |


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]