Hello,
I'm having some problems with inheritance.
The following code compiles and runs as expected: It prints out Hey: 1, since SomeFunction returns true.
#include <iostream>
class Base
{
public:
virtual bool SomeFunction(const int& A) const = 0;
};
class Derived : public Base
{
public:
void hey() const;
//bool SomeFunction(const int& A, int& B) const { return false; }
};
class DerivedOfDerived : public Derived
{
public:
bool SomeFunction(const int& A) const { return true; }
};
void Derived::hey() const
{
std::cout << "Hey: " << SomeFunction(5) << std::endl;
}
int main(int argc, char **argv)
{
DerivedOfDerived Ouch;
Ouch.hey();
return 0;
}
But if I uncomment the line bool SomeFunction(const int& A, int& B) const { return false; }
which should not affect anything, since I'm never even calling SomeFunction with 2 integers, it doesn't compile with the message:main.cpp:24:40: error: no matching function for call to ‘Derived::SomeFunction(int) const’
What? Why did Derived stopped being a child of Base? Isn't that very weird behaviour? Is this a bug in GCC 4.7.2? I think it should be a bug. Or can someone explain to me why this is?
Thank you!
Xorlium