class A defines copy operator, destructor and operator=. (Rule of Three)
If B inherits from A:
- the destructor will be called automatically
- I need to chain the constructor
operator=… should I define it explicitly for the classB?
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.
No, it’s unnecessary.
If you read carefully the Rule of Three, you will notice that nothing is said about a base class, the decision is made solely on the class proper attributes and behavior.
(Check this example on ideone)
This is actually the true power of encapsulation. Because you succeeded, using the Rule of Three, in making the behavior of the base class sane, its derived classes need not know whether the copy constructor is defaulted by the compiler or implemented manually (and complicated), all that matters for a user (and a derived class is a user), is that the copy constructor performs the copy.
The Rule of Three reminds us of an implementation detail to help achieve correct semantics. Like all implementation details, it matters only to the implementer and maintainer of this class.