[C++-sig] make_constructor issues
Ralf W. Grosse-Kunstleve
rwgk at yahoo.com
Fri Jul 23 22:46:20 CEST 2004
--- Stefan Seefeld <sseefeld at art.ca> wrote:
> well, the reason I'm asking because I found it counter-intuitive.
> Having defined a wrapper via
> class_<Foo> foo("Foo");
> I'd expect to pass values around, not Foo pointers. If it is
> a limitation of make_constructor, it should be documented.
AFAICT the behavior of class_<Foo> foo("Foo") isn't affected in any way by the
use of make_constructor. David, is this correct?
Speculating: David chose to implement make_constructor the way you see it to
avoid the requirement that the wrapped type must be copy-constructable. I guess
he could have provided another make_constructor overload that copies the new
instance but for some reason that wasn't considered worthwhile or even counter
productive. With the implementation as is people are forced to think about the
extra copy, and more likely than not are lead to write code which avoids it.
> It's not an issue, though, in this particular case.
Glad this is the case.
> wrapping legacy code, and the Foo in question is a small
> structure, which however, isn't properly initialized in its
> default constructor, so instead of using that I'd like to
> make a factory that does the initialization...
To me it seems the best implementation of the factory should return
auto_ptr<Foo> or shared_ptr<Foo> in order to avoid a copy.
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
More information about the Cplusplus-sig