while creating a hierarchy of classes I ran into a strange problem: it seems the compiler doesn't inherit virtual functions with the same name but different signature if only one of them is overridden in a derived class.
This is the smallest piece of code I could see the problem appear:
Expand|Select|Wrap|Line Numbers
- class UserType
- {
- public:
- UserType(float x) : x(x) {}
- float x;
- };
- class Base
- {
- public:
- Base() : data(0) {}
- virtual const UserType& Data() const { return data; }
- virtual void Data(const UserType& value) { data = value; }
- private:
- UserType data;
- };
- class D1 : public Base
- {
- };
- class D2 : public D1
- {
- virtual void Data(const UserType& value) { D1::Data(value); }
- };
- int main()
- {
- D2 d;
- d.Data();
- return 0;
- }
main.cpp: In function `int main()':
main.cpp:32: error: no matching function for call to `D2::T()'
main.cpp:26: error: candidates are: virtual void D2::T(const UserType&)
Why does this happen? I thought that any public function of a base class can be called in a derived, but in this case something is amiss.
Thanks in advance,
Harinezumi