[C++-sig] C++ static function as __init__
Piotr Jaroszyński
p.jaroszynski at gmail.com
Thu Jun 14 02:50:43 CEST 2007
On Thursday 14 of June 2007 02:29:27 Alex Mohr wrote:
> Does something like this work for you?
>
> struct Foo {
> Foo() {}
> static Foo *init_me() {
> return new Foo;
> }
> };
>
> class_<Foo>("Foo", no_init)
> .def("__init__", make_constructor(Foo::init_me));
>
> I forget if you need manage_new_object in there or not...
I somehow missed the make_constructor before posting and found it just before
receiving your reply. I did exactly the same but used shared_ptr instead of
the raw pointer as I keep the real Foo in a shared_ptr anyway (probably, it
doesn't matter, but shouldn't hurt, right?)
Thanks and sorry for the noise :]
--
Best Regards,
Piotr Jaroszyński
More information about the Cplusplus-sig
mailing list