gcc -Woverloaded-virtual
Aurélien Gâteau
aurelien.gateau at free.fr
Sat Nov 24 22:59:25 GMT 2007
Since this warning is on, I have been hitting warnings in jobclasses.h a bit
too much. Attached patch fixes those with "using KCompositeJob::bla;"
lines. Is it ok to apply?
Note that fixing the warning gets really interesting if the "offending"
method takes optional parameters. Look at this example
---
class KCompositeJob {
public:
virtual void addSubjob(KJob*);
};
class KIO::Job : public KCompositeJob {
public:
virtual void addSubjob(Job*, bool inheritData = true);
};
---
My first attempt was this:
---
class KIO::Job : public KCompositeJob {
public:
virtual void addSubjob(Job*, bool inheritData = true);
private:
using KCompositeJob::addSubjob;
};
---
But it doesn't work: gcc complains calling addSubjob(Job*) is ambiguous.
Instead I had to do this:
---
class KIO::Job : public KCompositeJob {
public:
virtual void addSubjob(Job*, bool inheritData); /* <- no more default */
void addSubjob(Job* job) { addSubjob(job, true); }
private:
using KCompositeJob::addSubjob;
};
---
Note that the "using" line is still necessary because even without the
overloaded parameter, the signatures of the two methods are still
different: KCompositeJob::addSubjob() accepts a KJob* while
KIO::Job::addSubjob() takes a KIO::Job* (this one had me confused for a
while).
Aurélien
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kdelibs_fix_overloaded_warnings_jobclasses.diff
Type: text/x-diff
Size: 1368 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20071124/761bef67/attachment.diff>
More information about the kde-core-devel
mailing list