Here is my simplified code which requires your valuable comments about poorly implemented polymorphism.
class X
{
public:
void test();
protected:
virtual void foo() const = 0;
};
class Y : public X
{
public:
void foo(){ cout << "hello" << endl; }
};
int main()
{
X *obj = new Y();
}
I get the following error at compilation.
test.cpp: In function ‘int main()’:
test.cpp:23: error: cannot allocate an object of abstract type ‘Y’
test.cpp:14: note: because the following virtual functions are pure within ‘Y’:
test.cpp:9: note: virtual void X::foo() const
Should be
Because
and
are not the same function.