views:

23

answers:

2

Hello,

I just got stuck with the following C++ compiler error:

no matching function for call "EPTDerivedException::HandleClass( BaseClass& )"
candidates are: void EPTDerivedException::HandleClass( DerivedClass )

I cannot explain this, because there should be a function HandleClass( BaseClass ). This is the calling code:

BaseClass oBase;
EPTDerivedException* pException2 = new EPTDerivedException;
pException2->HandleClass( oBase );

And this is the code for EPTDerivedException:

class EPTDerivedException : public EPTException
{
public:
    EPTDerivedException();
    // generic function
    void HandleClass( DerivedClass oClass ) { Q_UNUSED(oClass); }
};

And for the base class:

class EPTException
{
public:
    EPTException( QString strName );
    // specialized function
    void HandleClass( BaseClass oBase ) { Q_UNUSED(oBase); }
private:
    QString m_strName;
};

The strange things is also, that when I recompile (make clean; make) the code, I get the error message. If I add a space " " in the calling code (main.cpp) - the compiling afterwards is successful - and I have no idea why...

Thanks a lot,

Charly

PS: I use gcc 4.4.5 with Debian Squeeze, the qt-creator as IDE with qt 4.6 - but this problem is independent from Qt.

+1  A: 

I'm not sure why you think there should be a EPTDerivedException::HandleClass( BaseClass oBase ) function. There's no such declaration.

Perhaps you need to add using EPTException::HandleClass; to EPTDerivedException ?

MSalters
Exactly, `void HandleClass( DerivedClass oClass ) { Q_UNUSED(oClass); }` is the only HandleClass in DerivedClass, as the compiler says. Having that there hides the base class method unless you add "using" as recommended in this answer. Separately, the code should probably accept Based and DerivedClass by reference or const reference, avoiding a relatively slow copy.
Tony
thank a lot.yes, this was only an example. Originally I'm working with QSharedPointer - which cause the same problem - but cause very ugly error messages - so I decided not to post them here :)
Charly