You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to convert a python object to a cpp object for processing in cpp code. Here's what I met.
I create a class in cpp where one of the member is sons, containing 3 pointers of the object itself, the other is location, meaning the (x,y,z) location of the Node. Also, I create a corresponding class in python.
My target is to convert a python object into a cpp object, so I write a function called Node_p2cpp.
The problem I met is that after conversion, the cpp object became very weird, the location of the sons is randomly changing all the time, and the number of the sons is not right, sometimes may throw a RuntimeError: Could not allocate list object! bug.
What is going on? Any help would be appreciated! And here's the minimum executable code.
importexampleclassNode:
def__init__(self, sons, location):
self.sons=sons#suppose everynode has 3 sonsself.location=location# (x,y,z) coordinatedefNode_p2cpp(Node):
sons= []
foriinrange(3):
if(Node.sons[i] isnotNone):
sons.append(Node_p2cpp(Node.sons[i]))
else:
sons.append(None)
new_Node=example.Node(sons,Node.location)
returnnew_NodeNode1=Node([None,None,None],[0.1,0.1,0.1])
Node2=Node([Node1,None,None],[0.2,0.2,0.2])
root=Node([Node2,None,None],[0.3,0.3,0.3])
print("location and number of sons of the first son before conversion...")
print(root.sons[0].location)
print("location and number of sons of the first son after conversion...")
cpp_root=Node_p2cpp(root)
print(cpp_root.sons[0].location)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to convert a python object to a cpp object for processing in cpp code. Here's what I met.
I create a class in cpp where one of the member is
sons
, containing 3 pointers of the object itself, the other islocation
, meaning the (x,y,z) location of the Node. Also, I create a corresponding class in python.My target is to convert a python object into a cpp object, so I write a function called
Node_p2cpp
.The problem I met is that after conversion, the cpp object became very weird, the location of the sons is randomly changing all the time, and the number of the sons is not right, sometimes may throw a
RuntimeError: Could not allocate list object!
bug.What is going on? Any help would be appreciated! And here's the minimum executable code.
example.cpp
example.py
Beta Was this translation helpful? Give feedback.
All reactions