[C++-sig] function as custom ctor

David Abrahams dave at boost-consulting.com
Sun Nov 24 01:16:07 CET 2002


"Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com> writes:

> --- David Abrahams <dave at boost-consulting.com> wrote:
>> > Can I pass this funktion to boost.python in a way, that I could be used as
>> > ctor? Something like this:
>> >
>> > class_<Blob>("Blob",init<>())
>> >     .def( ??? , createBlob );
>> >
>> > and then from Python:
>> >
>> > data = "a string with data to be passed to the blob"
>> > blob = Blob(data)
>> 
>> Not quite, but you can fake it:
>> 
>> First expose your class with no_init, then expose createBlob as
>> "Blob".
>
> Can there be both a class_<Blob>("Blob", ...) /with constructors/
> and a free factory function def("Blob", ...)? Can there even be
> multiple constructors and factory functions? 

Not using the fakery technique above. However, it should be fairly
simple to make this capability available in a more-straightforward
manner. I'll take a look at it.

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list