【问题标题】:The type in a dynamic_cast must be a pointer or reference to a complete class type, or void *dynamic_cast 中的类型必须是指向完整类类型的指针或引用,或者 void *
【发布时间】:2012-10-19 11:06:24
【问题描述】:

我希望有人能理解为什么下面的代码会失败。我正在尝试从 osg::Node* 节点对象获取 PositionAttitudeTransform (Openscenegraph 类)的实例。但是下面用粗体显示编译器错误。

 void CameraPosCallbackUpdate::operator()(osg::Node* node, osg::NodeVisitor* nv)
{ 
   // other code goes here

    osg::PositionAttitudeTransform* pat = dynamic_cast<osg::PositionAttitudeTransform*> (node);

}

IntelliSense:dynamic_cast 中的类型必须是指向完整类类型的指针或引用,或 void *

请帮助我以正确的方式访问我的对象,我希望能帮助我理解这里的问题,因为我相信演员应该是可能的。

http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a00529.html

【问题讨论】:

  • 您需要出示node的声明。正如错误消息所说,它应该是一个完整类型的指针或引用。
  • 代码更新了更多关于节点来自哪里的细节。
  • 类型实际上是完整的吗?从这里可以看到它的定义吗?
  • 编译器对你说你没有包含 osg::PositionAttitudeTransform 实现

标签: c++ openscenegraph


【解决方案1】:

我相信你必须#include 包含class osg::PositionAttitudeTransform 的主体的头文件。
dynamic_cast 在目标类的主体不可见时会给出这样的错误。

这里是类似的error reproduced in g++

【讨论】:

  • 谢谢。我不得不删除#include 并用#include 替换它。
猜你喜欢
  • 2018-05-25
  • 2016-03-15
  • 2012-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-06
  • 2012-01-02
  • 1970-01-01
相关资源
最近更新 更多