Jump to content

[SOLVED] smartpointer casting?


photo

Recommended Posts

Hi,

 

suppose I have:

 

NodePtr node ;

ObjectMeshDynamicPtr mesh ;

 

how does one go about doing the following?

 

1. node = mesh ;

 

2. ((ObjectMeshDynamicPtr) node)->some_mesh_function () ;

(where it is known that node is really a mesh, see 1.)

 

 

Just trying operator= or regular casting creates interesting errors, so looked around a bit and found that the Ptr template does have a .get() function to return a Type*, but not a corresponding .set() (that could be given a regular casted c++ pointer)

 

Any way to do this, or impossible?

Link to comment
NodePtr node;
ObjectMeshDynamicPtr mesh = ObjectMeshDynamic::create(node);
mesh->some_mesh_function(); 

 

that works (or at least compiles) going from NodePtr to ObjectMeshDynamicPtr, but not the other way around. ie. assigning a NodePtr a ObjectMeshDynamicPtr:

 

NodePtr node ; // uninitialised
ObjectMeshDynamicPtr mesh ; // references created mesh object

node = mesh ;

or

node = Node::create (mesh) ;

 

The Node class does not seem to have that create() member

Link to comment

Solved it for now by querying a script function to return a NodePtr when given the node ID of the mesh.

 

Still curious though if it's (im)possible to do it on the C++ side?

Link to comment
×
×
  • Create New...