博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++ 句柄类和继承
阅读量:4087 次
发布时间:2019-05-25

本文共 1626 字,大约阅读时间需要 5 分钟。

15.8. Handle Classes and Inheritance

Unfortunately, using pointers or references puts a burden on the users of our classes. We saw one such burden in the previous section that discussed the inter-actions between objects of inherited types and containers.

A  common technique in C++ is to define a so-called cover or handle class  .  The handle class stores and manages a pointer to the base class. The type of the object to which that pointer points will vary; it can point at either a base- or a derived-type object.Users access the operations of the inheritance hierarchy through the handle. Because the handle uses its pointer to execute those operations, the behavior of virtual members will vary at run time depending on the kind of object to which the handle is actually bound. Users of the handle thus obtain dynamic behavior but do not themselves have to worry about managing the pointer.

Handles that cover an inheritance hierarchy have two important design considerations: 

As with any class that holds a pointer (Section 13.5, p. 492), we must decide what to do about copy control. Handles that cover an inheritance hierarchy typically behave like either a  smart pointer (Section 13.5.1, p. 495) or a value (Section 13.5.2, p. 499). 

The handle class determines whether the handle interface will hide the inheritance hierarchy or expose it.If the hierarchy is not hidden, users must know about and use objects in the underlying hierarchy.

There is no one right choice among these options; the decisions depend on the details of the hierarchy and how the class designer wants programmers to interact with those class(es).

转载地址:http://hyyii.baihongyu.com/

你可能感兴趣的文章
bw项目抱佛脚入门资料-1.理论基础
查看>>
bw项目抱佛脚入门资料-2.按照指标创建BW数据存储对象
查看>>
bw项目抱佛脚入门资料-3.源系统和数据源
查看>>
bw项目抱佛脚入门资料-4.数据存储对象和转换
查看>>
ABAP项目砖家之旅-基础篇
查看>>
ABAP项目砖家之旅-语法和开发对象篇
查看>>
给宝宝做一个cocos免费游戏-故事和开始界面
查看>>
给宝宝做一个cocos免费游戏-Node树和场景制作
查看>>
cocos摇杆、按键和角色动画制作
查看>>
cocos UI、地图和关卡文本制作(一)
查看>>
cocos UI、地图和关卡文本制作(二)
查看>>
COCOS敌人和AI制作
查看>>
bw项目抱佛脚入门资料-5.处理链和计划任务
查看>>
cocos角色和敌人行为互动脚本制作
查看>>
ABAP项目砖家之旅-alv项目实战
查看>>
ABAP项目砖家之旅-screen和表单项目实战
查看>>
ABAP项目砖家之旅-ABAP对象命名规则
查看>>
SAP接口集成-PO/PI-SLD配置
查看>>
SAP接口集成-abap调用外部数据库
查看>>
abap实现大数据-echar调用
查看>>