Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

like image 994
Kobojunkie Avatar asked Oct 30 '12 05:10

Kobojunkie


People also ask

What is the use of dynamic_cast in C++?

The primary purpose for the dynamic_cast operator is to perform type-safe downcasts. A downcast is the conversion of a pointer or reference to a class A to a pointer or reference to a class B , where class A is a base class of B .

What does dynamic_cast return in C++?

[edit] SyntaxIf the cast is successful, dynamic_cast returns a value of type new-type. If the cast fails and new-type is a pointer type, it returns a null pointer of that type. If the cast fails and new-type is a reference type, it throws an exception that matches a handler of type std::bad_cast.

Can dynamic_cast throw exception?

dynamic_cast will no longer throw an exception when type-id is an interior pointer to a value type, with the cast failing at runtime. The cast will now return the 0 pointer value instead of throwing.

What does dynamic cast of a reference return if it fails?

A failing dynamic cast to a reference type throws a bad_cast exception. A dynamic cast with a reference is a good way to test for a coding assumption.


1 Answers

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++.

like image 188
iammilind Avatar answered Oct 14 '22 03:10

iammilind