开发者

How to wrap c++ object with boost.Python, so that Python will never call it destructor automatically

开发者 https://www.devze.com 2023-03-02 04:22 出处:网络
For example, I have C++ class \"A\", and python class \"B\". Class \"A\" wrapped with boost::python, so I can use it in my python code. Class \"B\" has a member of type \"A\", I create 开发者_运维知识

For example, I have C++ class "A", and python class "B". Class "A" wrapped with boost::python, so I can use it in my python code. Class "B" has a member of type "A", I create 开发者_运维知识库it in constructor of "B". When I remove my object of class "B", it automatically calls destructor of "A" in C++. I want to avoid this call, so that "B" will not be responsible for its member "A" (that is wrapped c++ object). So, I want to remove my "B" object, and still have "A" in memory.


You should keep a pointer in your "B Class" to the "A Class object", So that when the "B object" is destructed the "Class A Object" is not reclaimed.

EDIT:

I think this could solve your problem:

aObjectPTR = POINTER(aObj)

Now, you have a pointer called "aObjectPTR". place instead of "AObj" the name of your A Class Object. After that, you have a pointer pointed to the A Class Object, so that the pointer(aObjectPTR) will only be reclaimed, not the object it point to.

0

精彩评论

暂无评论...
验证码 换一张
取 消