gcc -Woverloaded-virtual
Michael Pyne
michael.pyne at kdemail.net
Sat Nov 17 19:06:25 GMT 2007
On Saturday 17 November 2007, André Wöbbeking wrote:
> On Friday 16 November 2007, Allen Winter wrote:
> > -Woverloaded-virtual (C++ only)
> > Warn when a function declaration hides virtual functions
> > from a base class. For example, in:
> >
> > struct A {
> > virtual void f();
> > };
> >
> > struct B: public A {
> > void f(int);
> > };
> >
> > the "A" class version of "f" is hidden in "B", and code
> > like:
> >
> > B* b;
> > b->f();
> >
> > will fail to compile.
>
> It can be very handy but there're too many false positives, e.g. if
> virtual void A::f(int) also exists. IMO too many to make this a default
> option.
If virtual void A::f(int) exists then B::f() is still hidden, so the warning
still applies. I honestly didn't know the function hiding issue was really
this bad but it is.
If you want to make A::f() accessible in B you have to do something like:
struct B : public A {
using A::f;
void f(int) { ... }
};
Regards,
- Michael Pyne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20071117/b65e6364/attachment.sig>
More information about the kde-core-devel
mailing list