如何将dynamic_cast与指向子类的指针数组一起使用

问题描述 投票:0回答:1

我有一个指向对象类 e_t 的指针数组:

class e_t {...};

我写了一个模板类:

template <class E = e_t>
class cursor_t 

     { cursor_t(e_t ** &_source, size_t _total);

       e_t ** &Source;
       size_t  Total;

       E **First();
       E **Last();
       E **Skip(E **, short);
     };

对于每个功能,我都会

for(_x to this->_total
this->Source
并在第一个、最后一个或跳过的位置停止
dynamic_cast<E *>(*(this->Source + _x))
...工作正常并且正确停止...

问题出现在返回结果上!为什么我不能将

e_t **
用作
E **
(知道
E
总是从
e_t
下降)?

return dynamic_cast<E **>(this->Source + _x);
在编译时总是失败...

我正在使用 cbuilder 5

c++ arrays dynamic-cast
1个回答
0
投票

谢谢大家!

我发现...

我应该对数组的1个指针使用dynamic_cast,但我将对整个数组使用reinterpret_cast...

© www.soinside.com 2019 - 2024. All rights reserved.