class iostream : public istream, public ostream { // very simplified // ...};
istream provides the interface to input operations; ostream provides the interface to output operations. iostream provides the union of the istream and ostream interfaces and the synchronization needed to allow both on a single stream.istream提供面向输入操作的接口;ostream提供了面向输出操作的接口iostream提供了istream和ostream接口的结合,同时需要在两个独立的接口之间进行同步Note(注意)This is a very common use of inheritance because the need for multiple different interfaces to an implementation is common and such interfaces are often not easily or naturally organized into a single-rooted hierarchy.由于经常会出现一个实现需要多个不同接口的情况,而且这样的接口通常不容易或者无法自然地组织成一个单根继承,使用多重继承成为非常普通的做法Note(注意)Such interfaces are typically abstract classes.这样的接口一般都是抽象类Enforcement(实施建议)???原文链接:https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c135-use-multiple-inheritance-to-represent-multiple-distinct-interfaces觉得本文有帮助?请分享给更多人更多精彩文章欢迎关注【面向对象思考】面向对象开发,面向对象思考
(图片来源网络,侵删)
0 评论