Is it good practice to protect the constructor of the base class if I want to avoid instances of it? I know that I could also have a clean virtual dummy, but that seems weird ...
Pay attention to the following code:
#include <iostream>
using std::cout;
using std::endl;
class A
{
protected:
A(){};
public:
virtual void foo(){cout << "A\n";};
};
class B : public A
{
public:
void foo(){cout << "B\n";}
};
int main()
{
B b;
b.foo();
A *pa = new B;
pa->foo();
return 0;
}
Is there a flaw or side effect that I do not see?
source
share