Topic: further proposal for virtual overrides


Author: "Bruce Mellows" <bruce+101@wakethegimp.org>
Date: Thu, 4 Aug 2005 21:35:53 CST
Raw View
The current mechanism for overriding a virtual function requires the
signature to match exactly, which is as it should be, however, it would
also be nice to be able to specify that a method with the correct
signature is the override rather than having to use the same name.

For example...

class BaseOne
{
public:
  BaseOne();
  ~BaseOne();
  // etc including public inline to access Do()
private:
  virtual void Do(); // horrible name begging for a collision
};

class BaseTwo
{
public:
  BaseTwo();
  ~BaseTwo();
  // etc including public inline to access Do()
private:
  virtual void Do(); // horrible name with a collision
};

class Derived : public BaseOne, public BaseTwo
{
  // blah blah
private:
  void DoOne() using BaseOne::Do;
  void DoTwo() using BaseTwo::Do;
};

With the use of 'using' (look - no new keyword even though the
syntactic logic is wrong), I am telling the compiler which methods I
want in the virtual function table and exactly where, rather than it
trying to deduce it itself.

Alternately, if I had declared a 'void Derived::Do()', it would be the
override for both base classes, but they may intend completely
different functionality, and how do I resolve which was which without
having to change the base classes, which may not be permitted.

Finally the compiler can complain it the signatures do not match, or if
BaseOne::Do or BaseTwo::Do were not virtual.

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]