[Qt-interest] Problem with Base Class Method in Derived Class
Duane Hebert
spoo at flarn.com
Thu May 7 14:25:32 CEST 2009
"Shimaron Greywolf" <shimaron at furry.de> wrote in message news:DF5E5C4D-815A-4850-A189-D1B85A30181B at furry.de...
> Here's one strange problem - probably not really a Qt one, but probably someone can help.
>
> I thought I had my share of C++ design and coding, but the following was new to me. Consider this code:
>
> ===== test.h
>
> #include <QString>
> class x
> {
> public:
> virtual ~x();
> virtual void some_method(const QString i);
> };
>
> class xx : public x
> {
> public:
> virtual void some_method(const int i);
> virtual ~xx();
> };
>
> ====== test.cpp
>
> #include <QDebug>
> #include "test.h"
> int main()
> {
> xx * yy = new xx();
> yy -> some_method((int)65);
> yy -> some_method(QString("foo"));
> }
>
>
>
> x::~x() {}
> void x::some_method(const QString i) {qDebug()<<"x::QString";}
> void xx::some_method(const int i) {qDebug()<<"xx::int";}
> xx::~xx() {}
>
>
> =========
>
> My expectation was that in the new xx object, I'd have access to the base class method some_method(const QString) - which I
> don't, as the compiler tells me:
>
> src# make
> compiling test.cpp
> test.cpp: In function ‘int main()’:
> test.cpp:7: error: no matching function for call to ‘xx::some_method(QString)’
> test.h:12: note: candidates are: virtual void xx::some_method(int)
> test.cpp: At global scope:
> test.cpp:13: warning: unused parameter ‘i’
> test.cpp:14: warning: unused parameter ‘i’
> make: *** [test.o] Error 1
In the derived class (xx) try putting :
using x::some_method; to bring it into scope.
More information about the Qt-interest-old
mailing list