How can I hide the default constructor from consumers? I tried to write in private but got compilation issues.
solution is:
class MyInterface
{
public:
MyInterface(SomeController *controller) {}
};
class Inherited : public MyInterface
{
private:
Inherited () {}
public:
Inherited(SomeController *controller)
{
}
};
In your case, since you have already provided a constructor that takes one parameter
SomeController*, compiler doesn’t provide any default constructor for you. Hence, default constructor is not available.ie,
will cause compiler to say no appropriate constructor.
If you want to make constructor explicitly not available then make the same as private.
EDIT for the code you have posted:
You need to call base class
MyInterfaceconstructor (with single parameter) explicitly. Otherwise, by default the derived class constructor (Inherited) will look for Base class default constructor which is missing.class Inherited : public MyInterface
{
private:
Inherited ();
public: