B
Brad Pepers
For the life of me I can't see why this code won't compile even though its
very simple. Any hints? I get errors in NumberValcon::format(int) when it
tries to call format() but why doesn't it use the format() in the parent
Valcon class? Also there is an error in the main() code when trying to use
MoneyValcon::format(int) but why doesn't main use the one from NumberValcon
which is the parent of MoneyValcon? This is on all SuSE 9.2 using g++
version 3.3.4.
Here is the code:
class Valcon {
public:
Valcon();
virtual ~Valcon();
virtual int format()=0;
};
class NumberValcon: public Valcon {
public:
NumberValcon();
~NumberValcon();
int format(int foo);
protected:
int _foo;
};
class MoneyValcon: public NumberValcon {
public:
MoneyValcon();
~MoneyValcon();
int format();
};
Valcon::Valcon()
{
}
Valcon::~Valcon()
{
}
int
Valcon::format()
{
return 0;
}
NumberValcon::NumberValcon()
{
}
NumberValcon:: ~NumberValcon()
{
}
int
NumberValcon::format(int foo)
{
_foo = foo;
return format();
}
MoneyValcon::MoneyValcon()
{
}
MoneyValcon::~MoneyValcon()
{
}
int
MoneyValcon::format()
{
return 5;
}
int main()
{
MoneyValcon foo;
foo.format(10);
return 0;
}
The compile errors are:
bpepers@deth:~> g++ -c -Wall foo1.cpp
foo1.cpp: In member function `int NumberValcon::format(int)':
foo1.cpp:54: error: no matching function for call to
`NumberValcon::format()'
foo1.cpp:52: error: candidates are: int NumberValcon::format(int)
foo1.cpp: In function `int main()':
foo1.cpp:74: error: no matching function for call to
`MoneyValcon::format(int)'
foo1.cpp:67: error: candidates are: virtual int MoneyValcon::format()
distcc[25591] ERROR: compile foo1.cpp on localhost failed
very simple. Any hints? I get errors in NumberValcon::format(int) when it
tries to call format() but why doesn't it use the format() in the parent
Valcon class? Also there is an error in the main() code when trying to use
MoneyValcon::format(int) but why doesn't main use the one from NumberValcon
which is the parent of MoneyValcon? This is on all SuSE 9.2 using g++
version 3.3.4.
Here is the code:
class Valcon {
public:
Valcon();
virtual ~Valcon();
virtual int format()=0;
};
class NumberValcon: public Valcon {
public:
NumberValcon();
~NumberValcon();
int format(int foo);
protected:
int _foo;
};
class MoneyValcon: public NumberValcon {
public:
MoneyValcon();
~MoneyValcon();
int format();
};
Valcon::Valcon()
{
}
Valcon::~Valcon()
{
}
int
Valcon::format()
{
return 0;
}
NumberValcon::NumberValcon()
{
}
NumberValcon:: ~NumberValcon()
{
}
int
NumberValcon::format(int foo)
{
_foo = foo;
return format();
}
MoneyValcon::MoneyValcon()
{
}
MoneyValcon::~MoneyValcon()
{
}
int
MoneyValcon::format()
{
return 5;
}
int main()
{
MoneyValcon foo;
foo.format(10);
return 0;
}
The compile errors are:
bpepers@deth:~> g++ -c -Wall foo1.cpp
foo1.cpp: In member function `int NumberValcon::format(int)':
foo1.cpp:54: error: no matching function for call to
`NumberValcon::format()'
foo1.cpp:52: error: candidates are: int NumberValcon::format(int)
foo1.cpp: In function `int main()':
foo1.cpp:74: error: no matching function for call to
`MoneyValcon::format(int)'
foo1.cpp:67: error: candidates are: virtual int MoneyValcon::format()
distcc[25591] ERROR: compile foo1.cpp on localhost failed