The type in a dynamic_cast must be a pointer or reference to a complete class type, or void *

我们两清 提交于 2019-12-30 18:52:07

问题


I am hoping there is someone out there who understands why the code below fails. I am trying to get an instance of PositionAttitudeTransform (Openscenegraph class) from an osg::Node* node object. But there is the compiler error below in bold.

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

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

}

IntelliSense: the type in a dynamic_cast must be a pointer or reference to a complete class type, or void *

Please help me with correct way to access my object and I would appreciate help in understanding what the problem here is since I believe the cast should be possible.

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

回答1:


I believe you have to #include the header file which contains the body of class osg::PositionAttitudeTransform.
dynamic_cast gives such error when the body of the destination class is not visible.

Here is the similar error reproduced in g++.



来源:https://stackoverflow.com/questions/13133407/the-type-in-a-dynamic-cast-must-be-a-pointer-or-reference-to-a-complete-class-ty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!