[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: Problem with derived class function name the same as base class
From: Stephen Allewell <stephen () mirramar ! fsnet ! co ! uk>
Date: 2002-06-29 21:18:18
[Download RAW message or body]
Malte Starostik wrote:
> Am Saturday 29 June 2002 22:41 schrieb Stephen Allewell:
> > I have a class 'Editor' that is derived from QScrollView. QScrollView
> > has the function
> > QPoint contentsToViewport(const QPoint &p) to convert content
> > coordinates to viewport coordinates.
> > I also require to convert a QRect so I wrote the function:
> >
> > QRect Editor::contentsToViewport(QRect &r) {
> > return
> > QRect(contentsToViewport(r.topLeft()),contentsToViewport(r.bottomRight()));
> > }
> >
> > but when compiling I get the error that there is no matching function
> > for contentsToViewport(QPoint &) unless I explicitly use
> > QScrollView::contentsToViewport(...) which then compiles and works as
> > intended.
> >
> > I thought that it was possible to have different functions with the
> > same name as long as the parameters where different.
> >
> > Anyone have any idea why this doesn't work?
> Yes, a method in a derived class hides any method with the same name in the
> base class. You have two possibilities here:
>
> class Base
> {
> public:
> void doStuff( const QPoint& );
> };
>
> // Either:
> class Derived : public Base
> {
> public:
> void doStuff( const QPoint& p ) { Base::doStuff( p ); }
> void doStuff( const QRect& );
> };
>
> // Or, but doesn't work with older compilers:
> class Derived : public Base
> {
> public:
> using Base::doStuff;
> void doStuff( const QRect& );
> };
>
I would expect this if the functions had identical signatures, but
where the functions are uniquely defined, I would not have thought it
a problem for the compiler to use the base class function.
Thanks for the info, I'll use the work around for it.
Steve
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic