[C++-sig] discard reference
Mike Rovner
mike at nospam.com
Fri Sep 12 22:16:31 CEST 2003
Hi all,
I'm trying to find an elegant way of discarding python reference.
I have a pure virtual base class A, my class implementation AA and
a function with wants to take ownership of A*:
class A
{
virtual f1() = 0;
virtual ~A() {}
};
class AA : public A
{
AA(int) {...}
};
class B
{
void set_new_owner(A* a) { ... }
};
I shall use it that way:
b=B()
- in C++: b.set_new_owner(new AA(1));
- in Python: b.set_new_owner(AA(1))
Now I wrap it (according to FAQ) with auto_ptr<A*> and a small wrapper:
void set_new_owner_wrap(B& b, auto_ptr<A*> a) { b.set_new_owner(a.get());
a.release(); }
...
class_<A, auto_ptr<A*>, noncopyable>("A", no_init);
class_<AA, bases<A>, noncopyable>("AA", init<int>).def("f1", &AA::f1);
class_<B>("B").def("set_new_owner", &set_new_owner_wrap);
Now the problem: there is no autoconvertion from AA* to auto_ptr<A>.
What will be the correct way to solve the problem?
Regards,
Mike
More information about the Cplusplus-sig
mailing list