[C++-sig] init from free function instead of constructor

Stefan Seefeld seefeld at sympatico.ca
Wed Jan 24 21:04:40 CET 2007


John Reid wrote:
> Hmmm well it sounds helpful and looks interesting but I get some 
> compilation errors. I found this thread from 2004 saying the docs are 
> wrong: http://aspn.activestate.com/ASPN/Mail/Message/cpp-sig/2262368
> I think the thread is right and the docs are wrong :(. At least the docs 
> don't agree with the header file.

Hmm, I can't quite remember the whole context of that discussion.
However, I know that my code works (with g++ at least, not MSVC, mind you).
My factory function returns an auto_ptr<X>, where 'X' is the type being
exported via class_<X>. If yours returns a raw pointer, you may need
to specify a return_value_policy, or wrap with boost::python::ptr() to
give a hint at how you'd like the memory to be managed.

HTH,
		Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list