[C++-sig] Re: FW: Injected constructors
Roman Yakovenko
romany at actimize.com
Thu Jul 24 13:50:10 CEST 2003
> -----Original Message-----
> From: David Abrahams [mailto:dave at boost-consulting.com]
> Sent: Thursday, July 24, 2003 12:32 PM
> To: c++-sig at python.org
> Subject: [C++-sig] Re: FW: Injected constructors
>
>
> "Roman Yakovenko" <romany at actimize.com> writes:
>
> > Just a question what is wrong with static member function or global
> > function make_xxx?
>
> Good point. init_factory was going to be a global function, but I
> guess I like "make_init" much better than "init_factory". Thanks!
I think I was misunderstood. I will explain my self using code.
> > The idiom of constructing object and then making additional
> > initialization is already used in Boost.Python - borrowed function
> > for constructing handle.
>
> Sure; that's
>
> .def(init_factory(f))
>
> or, I guess:
>
> .def(make_init(f))
>
> right?
>
> > Also in Python code it will be written explicit what programmer is
> > going to do. Did I missed something?
>
> I don't know. What point are you trying to make with this remark?
class MyClass
{
...
MyClass(); //after constructing object stays in state 1
MyClass( int i ); //after constructing object stays in state 2
MyClass( const YourClass &x); //after constructing object stays in state 3
...
};
Now if I understand right there is a need in other state of the MyClass object.
MyClass make_myclass_from_other( const SomeOther &y );
BOOST_PYTHON_MODULE(staticmethod_ext)
{
class_<MyClass>
...
.staticmethod(make_myclass_from_other)
...
While in python I'll write
obj = MyClass.make_myclass_from_other( third_party_class )
As for me it is much clear then adding an other constructor for the class.
At the moment I wrote I thought about class that already has a few constructors.
Now I understand that it is not the only case. May be you have nice small class with
one constructor and you want to add an other one.
I propose those names: make_object / make_instance
> --
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
More information about the Cplusplus-sig
mailing list