[C++-sig] How can I store shared_ptr in python list ?
Kamil Zubair
kamilzubair at yahoo.com
Wed Apr 2 17:44:39 CEST 2008
Hi,
I'm trying to do this :
Python:
ptr_list=[]
def func(ptr, msg):
if "insert"==msg:
ptr_list.append(ptr)
elif "remove"==msg:
ptr_list.remove(ptr)
C++:
class MyClass{};
int main()
{
//initialize python
exec_file("func.py", global, global); //func.py is the code above
object func = global["func"];
shared_ptr<MyClass> mc(new MyClass());
func(mc, "insert");
func(mc, "remove"); <-- exception here
}
My question is how do I expose my class to python ? I tried class_<MyClass, shared_ptr<MyClass> >("MyClass") but it always fails when I tried to remove an already inserted object.
---------------------------------
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080402/3b6704e1/attachment.htm>
More information about the Cplusplus-sig
mailing list