PDA

View Full Version : Access from other class



champ
12th June 2010, 15:57
Hi

I have these files in my project:

/home/myproj/lib/myPlugin.h




class MYPROJ_EXPORT myPlugin : public QObject
{
Q_OBJECT

public:
virtual ~myPlugin();
virtual myPlugin * newInstance() const = 0;
virtual qreal speed() const;
virtual qreal direction() const;

protected:
myPlugin();

private:
Q_DISABLE_COPY( myPlugin )
};

}



/home/myproj/lib/myPlugin.cpp




#include "PositionProviderPlugin.h"



myProj::myPlugin::myPlugin()
{
}

myProj::myPlugin::~myPlugin()
{
}

qreal myProj::myPlugin::speed()
{
}

qreal myProj::myPlugin::direction()
{
}
#include "myPlugin.moc"


When I compile I get this error:

error: prototype for ‘qreal myProj::myPlugin::speed()’ does not match any in class ‘myProj::PositionProviderPlugin’
error: candidate is: virtual qreal myProj::myPlugin::speed() const

error: prototype for ‘qreal myProj::myPlugin::direction()’ does not match any in class ‘my::PositionProviderPlugin’
error: candidate is: virtual qreal myProj::myPlugin::direction() const

How can I correct this ?

Lykurg
12th June 2010, 16:00
add const to your definition! (as the error message says...)

qreal myProj::myPlugin::speed() const
{
}

SixDegrees
12th June 2010, 16:04
Your compiler is telling you everything you need to know. Function signatures must match EXACTLY, and your's don't, because you've dropped the 'const' specification from the implementation, just as the error message points out.