From kde-devel Sat Jun 29 21:18:18 2002 From: Stephen Allewell Date: Sat, 29 Jun 2002 21:18:18 +0000 To: kde-devel Subject: Re: Problem with derived class function name the same as base class X-MARC-Message: https://marc.info/?l=kde-devel&m=102538549813039 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 <<