PDA

View Full Version : Why can't I call base public method?



lni
13th April 2009, 20:17
This is weird. Any idea on this error?

The compiler (g++) complains

main.cpp: In function `int main()':
main.cpp:42: error: no matching function for call to `ClassB::zValue(QPointF, bool*)'
main.cpp:32: note: candidates are: virtual double ClassB::zValue(double, double, bool*) const
gmake: *** [main.o] Error 1




#include <QPointF>

class ClassA
{
public:

ClassA() {}
virtual ~ClassA() {}

virtual double zValue( double xpos, double ypos, bool* ok=0 ) const=0;
double zValue( const QPointF& xy, bool* ok=0 ) const;

};

double ClassA::zValue( const QPointF& xy, bool* ok ) const
{
return zValue( xy.x(), xy.y(), ok );
}

class ClassB : public ClassA
{
public:

ClassB() {}
~ClassB() {}

virtual double zValue( double xpos, double ypos, bool* ok=0 ) const;

};

double ClassB::zValue( double xpos, double ypos, bool* ok ) const
{
if ( ok ) *ok = true;
return xpos + ypos;
}

int main()
{
ClassB mess;

bool ok;
mess.zValue( QPointF( 0, 0 ), &ok );

}

caduel
13th April 2009, 20:34
the declaration is hidden by the subclass.
add the line

using ClassA::zValue;
to the subclass ClassB

HTH

lni
13th April 2009, 20:50
the declaration is hidden by the subclass.
add the line

using ClassA::zValue;
to the subclass ClassB

HTH

Thanks! First time seeing this!

Sheng
13th April 2009, 21:37
the declaration is hidden by the subclass.
add the line

using ClassA::zValue;
to the subclass ClassB

HTH


Thanks! First time seeing this!

better just use mess.ClassA::zValue(QPointF(0,0),&ok);