[C++-sig] make_constructor issues
Ralf W. Grosse-Kunstleve
rwgk at yahoo.com
Fri Jul 23 21:38:26 CEST 2004
--- Stefan Seefeld <sseefeld at art.ca> wrote:
> hi there,
> the wrapper 'python.hpp' header doesn't include
> the 'make_constructor.hpp' file. Shouldn't it ?
> Then I try to make
> Foo make_foo()
> Foo foo;
> return foo;
> a constructor (i.e. binding it to '__init__' via
> 'make_constructor'), but I get an error message about
> 'element_type' not being a member of Foo. The
> examples I'v found all use pointes, so I changed
> the 'make_foo' function to return a pointer.
> That works, but is not what I want to do.
Why not? It is just a technical detail that you have to adjust to. I.e. you
could to this (untested):
return shared_ptr<Foo>(new Foo(foo));
But this requires that Foo is copy-constructable and you incur a
runtime-penalty for executing the copy constructor. I'd generally prefer this:
shared_ptr<Foo> foo_ptr(new Foo);
Foo& foo = *foo_ptr;
Is this approach impractical in your environment? If so, what are the reasons?
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
More information about the Cplusplus-sig