objectCast 横向投射
我正在尝试用QT的objectCast替换代码中的所有dynamicCast。但我遇到了一些困难。这是我的对象的层次结构:
class ABase : public QObject
class IAbility; // Registered as Qt Interface
class ISize; // Registered as Qt Interface
class Derived : public ABase, public IAbility, public ISize; // Uses Q_INTERFACES
使用 objectCast 我可以将 Derived 转换为 ISize 或 IAbility。但是,在我的代码的某一点中,我想执行以下转换:Derived->ISize->IAbility。最后一次转换是我收到错误的地方。由于 IAbility 与 ISize 没有任何关系,因此这可能会导致问题。此时我可以进行动态转换,但我不想这样做。
I'm trying to replace all dynamicCasts in my code with QT's objectCast. But I've run into a bit of a snag. Here's the hierarchy of my objects:
class ABase : public QObject
class IAbility; // Registered as Qt Interface
class ISize; // Registered as Qt Interface
class Derived : public ABase, public IAbility, public ISize; // Uses Q_INTERFACES
Using objectCast I can convert a Derived to a ISize or IAbility. However, in one point of my code I want to perform the following conversion: Derived->ISize->IAbility. That last cast is where I get an error. Since IAbility does not relate to ISize in any way, that could cause a problem. I could do a dynamic cast at this point, but I'd rather not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您有三个选择:
我会选择选项 3,只是因为从抽象角度来说,它是强制程度最低的解决方案。
As I see it you have three options:
I would go for option 3, simply because it's the least forced solution, abstraction-wise.