Is a public constructor in an abstract class a codesmell?
c++
Solution
My opinion would be that the public constructor might be seen to be confusing, and as you say making it protected would be correct. I would say that a protected constructor correctly reinforces the impression that the only sensible use of an abstract class is to derive from it.
In fact, you only need to declare a constructor in an abstract class if it needs to do something, eg. initialise its own private members. I would then expect there to be other protected member functions that are helpful to derived classes.
EDIT:
Since no-one has posted any code and @sbi asked for some in a comment to OP, I thought I would post some:
class Base:
{
public: // The question is: should the ctor be public or protected?
// protected:
Base():i(0){} // ctor is necessary to initialise private member variable
public:
virtual ~Base(){} // dtor is virtual (but thats another story)
// pure virtual method renders the whole class abstract
virtual void setValue(void)=0;
protected:
int getValue(void){ return i;}
private:
int i;
};
Base b1; // Illegal since Base is abstract, even if ctor is public
Base& b2=makeBase(); //We can point to, or refer to a Base
b2.setValue(); // We're not sure what this does, but we can call it.
b2.getValue(); // Illegal since getValue is protected
Problem
Is a public constructor in an abstract class a codesmell? Making the constructor protected provides all of the access of which you could make any use. The only additional access that making it public would provide would be to allow instances of the class to be declared as variables in scopes that cannot access its protected members, but instances of abstract classes cannot be declared at all.