[C++-sig] function as custom ctor

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Tue Nov 19 18:01:12 CET 2002


--- 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? Is the order of the class_<> and free def statements
important?

Thanks,
        Ralf


__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com




More information about the Cplusplus-sig mailing list