Topic: virtual fn() = inherited::fn(); notation


Author: Marian Hellema <marian@atcmp.nl>
Date: Thu, 2 Mar 1995 09:46:39 GMT
Raw View
mhw@minster.york.ac.uk wrote:
>
> In the ARM passing mention is made of possibly extending the abstract
> virtual function syntax to disambiguate between multiply inherited
> functions, as in
>
>  class C: public A, public B {
>  public:
>   virtual void fn() = B::fn();
>  };
>
> (this being a shorthand for
>
>  class C: public A, public B {
>  public:
>   virtual void fn();
>  }
>
>  void C::fn()
>  {
>   B::fn();
>  }
>
> Has this been adopted by the committee, or are there movements in that
> direction. If not, were considerations made or has no-one made a strong
> enough case for adopting the syntax (such as showing a common usage of
> it).

I suppose you refer to page 236, 237 of the ARM.
In the errata to the ARM, it says:

" Replace page 237 by:

class LotterySimulation:    // class C, A and B in your example
   public Lottery,
   public GraphicalObject {
   // ...
   virtual int l_draw() = Lottery::draw; // no parentheses
   virtual void go_drw() = GraphicalObject::draw;
};

This would extend the pure virtual syntax in a natural manner.

However, it was noted by Doug McIlroy that this problem does have a
solution within C++. Renaming can be achieved through the introduction
of an extra class for each class with a virtual function that needs
to be overridden by a function with a different name plus a forwarding
function for each such function. For example:

class LLottery: public Lottery {
   virtual int l_draw() = 0;
   int draw() // overrides Lottery::draw
      { return l_draw(); }
};

class GGraphicalObject : public GraphicalObject {
   virtual int go_draw() = 0;
   void draw() // overrides GraphicalObject::draw
      { go_draw(); }

class LotterySimulation
   : public LLottery,
      public GGraphicalObject {
         // ...
         int l_draw();
         void go_draw();
};

Consequently, a language extension to express renaming is not
necessary and is only worthwhile if the need to resolve such name
clashes proves common."

Regards,
Marian Hellema





Author: schuenem@Informatik.TU-Muenchen.DE (Ulf Schuenemann)
Date: 2 Mar 1995 17:36:41 GMT
Raw View
mhw@minster.york.ac.uk writes:
|>
|>In the ARM passing mention is made of possibly extending the abstract
|>virtual function syntax to disambiguate between multiply inherited
|>functions, as in
|>
|> class C: public A, public B {
|> public:
|>  virtual void fn() = B::fn();
|> };

To disambiguate I would prefere "using", the replacement of the access-declaration:

 class C: public A, public B {
 public:
  using B::fn;
 };

This is more general than what I expect that the above mentioned mention of the
ARM means.
[ I had to reconsider my preference if the ARM were more general. I.e. any
const-expression of matching type would be allowed on the right side of the '='
where the left side is a virtual (more general: also non-virtual) memberfunction ].

Ulf Schuenemann

--------------------------------------------------------------------
Ulf Sch   nemann
Institut f   r Informatik, Technische Universit   t M   nchen.
email: schuenem@informatik.tu-muenchen.de




Author: mhw@minster.york.ac.uk
Date: 27 Feb 1995 15:14:02 GMT
Raw View
In the ARM passing mention is made of possibly extending the abstract
virtual function syntax to disambiguate between multiply inherited
functions, as in

 class C: public A, public B {
 public:
  virtual void fn() = B::fn();
 };

(this being a shorthand for

 class C: public A, public B {
 public:
  virtual void fn();
 }

 void C::fn()
 {
  B::fn();
 }

). The implication seemed to be that it would allow the function to be
optimised away easily by putting the address of the inherited function
in the classes virtual table (if I understand this right).

Has this been adopted by the committee, or are there movements in that
direction. If not, were considerations made or has no-one made a strong
enough case for adopting the syntax (such as showing a common usage of
it).

-Mark.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Mark H. Wilkinson <mhw@minster.york.ac.uk>  : Research student in user
University of York, England                 : interface management systems




Author: damian@cs.monash.edu.au (Damian Conway)
Date: Mon, 27 Feb 1995 19:14:34 GMT
Raw View
mhw@minster.york.ac.uk writes:

>In the ARM passing mention is made of possibly extending the abstract
>virtual function syntax to disambiguate between multiply inherited
>functions, as in

> class C: public A, public B {
> public:
>  virtual void fn() = B::fn();
> };

Surely, to be in any way consistent that should be:

  virtual void fn() = B::fn;

Now, is there any reason why the compiler could not make the same
optimization if it saw the current syntax:

  virtual void fn() { B::fn(); }

More importantly, is there any reason to perpetuate the dog ugly syntax of pure
virtual declaration?

damian
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  who: Damian Conway                 email: damian@bruce.cs.monash.edu.au
where: Dept. Computer Science        phone: +61-3-565-5184
       Monash University               fax: +61-3-565-5146
       Clayton 3168                  quote: "A pessimist is never disappointed."
       AUSTRALIA