
>抽象基类Abstract1和Abstract2.他们是无关的.
>一个派生自Abstract1和Abstract2的Foo类
我在一个编译单位,我没有关于Foo类的信息(没有声明,没有定义).只有Abstract1和Abstract2是已知的.
(实际上,Foo甚至在DLL中定义)
将dynamic_cast允许从Abstract1 *转换为Abstract2 *?这是标准吗?
解决方法 你所描述的是一种所谓的交叉角色.对于dynamic_cast< T(v),标准在[expr.dynamic.cast] / 8If
Cis the class type to whichTpoints or refers,the run-time
check logically executes as follows:If,in the most derived object pointed (referred) to by
v,vpoints (refers) to a public base class subobject of aCobject [..]Otherwise,if
vpoints (refers) to apublicbase class subobject of the most derived object,and the type of the most derived object
has a base class,of typeC,that is unambiguous andpublic,the
result points (refers) to theCsubobject of the most derived
object.
即使没有关于Foo在包含演员的翻译单元中的存在的信息,这将会工作.
你也应该看看this question.
总结以上是内存溢出为你收集整理的复杂的dynamic_cast在c全部内容,希望文章能够帮你解决复杂的dynamic_cast在c所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)