private继承的作用

这里有个demo,里面的Stack<T*> : private Stack<void *>,作者对此的解释如下

The partial specialization for other pointer types derives from Stack<void*> privately, since we are
merely using Stack<void*> for implementation purposes, and do not wish to expose any of its interface directly
to the user.

最开始我一直没明白这怎么就对外隐藏了Stack<void *>的interface了?

后来搞明白了,当然,没有直接隐藏Stack<void *>的interface因为其interface暴露在头文件中,准确的说,应该是禁止了把Stack<T*>的instance直接upper转型给Stack<void *>的reference或者pointer

因为如果private继承的话,upper转型是无法编译的,在demo里的代码有体现,这里就不啰嗦了。

点击下载demo

 

转载于:https://www.cnblogs.com/qrlozte/p/4386026.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值