If a class is always going to be inherited, does it make sense to make the constructor protected?
class Base
{
protected:
Base();
};
class Child : protected Base
{
public:
Child() : Base();
};
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That only makes sense if you don’t want clients to create instances of
Base, rather you intend it to be base-class of some [derived] classes, and/or intend it to be used by friends ofBase(see example below). Rememberprotectedfunctions (and constructors) can only be invoked from derived classes andfriendclasses.