正文

C++:14,Inheritance & Composition2006-10-21 21:31:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/wenzhuo316/19593.html

分享到:

1.       Code reuse in C++:

l         Create objects of your existing class inside the new class. This is called composition because the new class is composed of objects of existing classes.

l         Create a new class as a type of an existing class. You literally take the form of the existing class and add code to it, without modifying the existing class. This magical act is called inheritance, and most of the work is done by the compiler.

2.       When you inherit, you are saying, “This new class is like that old class.” You state this in code by giving the name of the class as usual, but before the opening brace of the class body, you put a colon and the name of the base class (or base classes, separated by commas, for multiple inheritance). When you do this, you automatically get all the data members and member functions in the base class.

3.       It’s also interesting that the order of constructor calls for member objects is completely unaffected by the order of the calls in the constructor initializer list. The order is determined by the order that the member objects are declared in the class.

阅读(2648) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册