Extending the C Standard Library through Inheritance
While it's often assumed that inheriting from C Standard Library classes is not desirable, there are notable exceptions.
Identifiable Classes for Inheritance
Determining whether a Standard Library class is intended for inheritance can be challenging. However, the following guidelines can provide some insight:
Derived Class Requirements
When inheriting from Standard Library classes, the Liskov Substitution Principle (LSP) should be applied. Observable behavior, such as the what() function in std::exception, should match the base class. Conformance to the Standard is less of a concern than correctness in this context.
Conclusion
While the Standard itself lacks explicit guidance on extending the Standard Library, it's crucial to carefully consider the intended usage of classes and apply principles of inheritance judiciously.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3