Can anyone explain why this doesn't work?
#include <iostream>
class Parent
{
public:
virtual int Add(int a, int b) = 0;
int Add(int a)
{
return this->Add(a,a);
}
};
class Child : public Parent
{
public:
int Add(int a, int b)
{
return a+b;
}
};
int main()
{
Child test;
std::cout << test.Add(2);
return 0;
}
It says:
error: no matching function call to 'Child::Add(int)'
The Child instance should be able to see the one argument Add function because it is inherited, right??
If I change the Child class to
class Child : public Parent
{
public:
int Add(int a, int b)
{
return a+b;
}
int Add(int a)
{
Parent::Add(a);
}
};
It works fine. I thought the whole idea of inheritance was that I didn't specifically have to tell the derived classes about these functions?
Thanks,
David