Topic: explicit overrides
Author: "Tony" <gottlobfrege@gmail.com>
Date: 27 Apr 2005 18:40:11 GMT Raw View
Microsoft has "explicit overrides"
(http://msdn.microsoft.com/library/en-us/vclang/html/vcrefexplicitoverrides.asp).
Are these possibly coming to C++ proper? Do any other compilers
support them yet?
FYI, a quick example:
class Base1
{
virtual int Func();
};
class Base2
{
virtual int Func();
};
class Derived : Base1, Base2
{
// explicitly override both Funcs:
virtual int Base1::Func()
{
cout << "called from code that sees me as a Base1";
}
virtual int Base2::Func()
{
cout << "called from code that sees me as a Base2";
}
};
This solves both the above multiple-inheritance case, as well as the
simple inheritance case where you THINK you are overriding Func, but
you are not:
class Derived1 : Base1
{
// explicit override way:
// this is a compile error, as Base1 does NOT
// have a Func that takes an int.
int Base1::Func(int x)
{
cout << "this doesn't actually compile";
}
// typical way:
// you intend to override Base1::Func,
// but you messed up the signature
// ('const' is enough to cause a problem!)
// so instead, you just defined your own Func,
// and hid Base1's Func.
int Func() const
{
cout << "implements Base1::Func... NOT ";
}
};
I've always wanted this syntax, but it wasn't until today that I
stumbled upon the fact the MS was already doing it.
Of course, I don't want to start using until it is standardized (or at
least widely supported, I guess).
---
[ 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 ]