[C++-sig] Shared pointers and new objects
Eric Jonas
jonas at MIT.EDU
Sun Feb 1 16:37:51 CET 2009
I am trying to return a shared pointer to a class Foo and then
test the results in python for equality, but they always seem to fail.
I've created the following two trivial classes:
class Foo : public boost::noncopyable
{
};
typedef boost::shared_ptr<Foo> pFoo_t;
class FooCreator
{
public:
pFoo_t createFoo() {
pFoo_t ft(new Foo);
intfoo = ft;
return ft;
}
pFoo_t getFoo() {
return intfoo;
}
pFoo_t intfoo;
};
That I expose with boost::python via:
class_<Foo, pFoo_t, boost::noncopyable>("Foo", no_init);
class_<FooCreator>("FooCreator")
.def("createFoo", &FooCreator::createFoo)
.def("getFoo", &FooCreator::getFoo);
Yet the following assert fails:
fc = FooCreator()
foo = fc.createFoo()
foo2 = fc.getFoo()
assert_equal(foo, foo2)
The above assert fails. I've tried using the newest boost::python, I've
looked through the mailing list archives and even asked on IRC, but I
still can't figure out which part of this process I'm doing incorrectly.
I've spent about 20 hours reducing my problem to this test case, and am
really stumped.
...Eric
More information about the Cplusplus-sig
mailing list