为什么不演这个? [英] Why won't this cast?

查看:58
本文介绍了为什么不演这个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类SORef {...};

class SelectedFORef:public SORef {...};

SOFORef SOCastToSOF(SORef sor){

SelectedFORef sof = nil;

sof = dynamic_cast< selectedFORef>(sor);

返回sof;

};


我遇到一个问题,即sor没有被转换为sof(变为零)

即使sor是下面的SelectedFORef。 (我有一个调试方法

详细内容和类型)。


我不是C ++专家。

什么是我做错了吗?


Mark

class SORef {...};
class SelectedFORef : public SORef {...};
SOFORef SOCastToSOF(SORef sor) {
SelectedFORef sof=nil;
sof=dynamic_cast<SelectedFORef>(sor);
return sof;
};

I am getting a problem where sor is not being cast to sof (becomes nil)
even though sor IS a SelectedFORef underneath. (I have a debug method
with details contents and type).

I am not a C++ expert.
What am I doing wrong?

Mark

推荐答案

mark写道:
mark wrote:

class SORef {...};

class SelectedFORef:public SORef {...};


SOFORef SOCastToSOF(SORef sor){

SelectedFORef sof = nil;
class SORef {...};
class SelectedFORef : public SORef {...};
SOFORef SOCastToSOF(SORef sor) {
SelectedFORef sof=nil;



什么是零?


-

Ian Collins。

What''s nil?

--
Ian Collins.


在文章< 5b ************* @ mid.individual.net> ;,

Ian Collins< ia******@hotmail.com写道:
In article <5b*************@mid.individual.net>,
Ian Collins <ia******@hotmail.comwrote:

mark写道:
mark wrote:

class SORef { ......};

class SelectedFORef:public SORef {...};

SOFORef SOCastToSOF(SORef sor){

SelectedFORef sof =零;
class SORef {...};
class SelectedFORef : public SORef {...};
SOFORef SOCastToSOF(SORef sor) {
SelectedFORef sof=nil;



什么是零?


What''s nil?



nil == NULL。

Pascal版本的NULL。

nil == NULL.
Pascal version of NULL.


mark写道:
mark wrote:

文章< 5b ************* @ mid.individual.net>,

Ian Collins< ia ****** @ hotmail.comwrote:
In article <5b*************@mid.individual.net>,
Ian Collins <ia******@hotmail.comwrote:

> mark写道:
>mark wrote:

>>类SORef {...};
类SelectedFORef:public SORef {...};

SOFORef SOCastToSOF(SORef sor){
SelectedFORef sof = nil;
>>class SORef {...};
class SelectedFORef : public SORef {...};
SOFORef SOCastToSOF(SORef sor) {
SelectedFORef sof=nil;


什么是零?

What''s nil?



nil == NULL。

Pascal版本的NULL。


nil == NULL.
Pascal version of NULL.



然后为什么隐藏它?你不能将NULL赋给一个类对象,只能指定一个指针。


你不能将dynamic_cast应用于类对象,只能引用一个

指向一个。

-

Ian Collins。

Then why hide it? You can''t assign NULL to a class object, only a pointer.

You can''t apply a dynamic_cast to a class object, only a reference of a
pointer to one.
--
Ian Collins.


这篇关于为什么不演这个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆