[C++-sig] How to manage smart pointer as return value of a factory?

David Abrahams dave at boost-consulting.com
Thu Feb 16 19:17:20 CET 2006


Julien <swell at netcourrier.com> writes:

> You are absolutely right i am using msvc and don't generate the RTTI 
> informations. If i do the change to allow RTTI and  it works perfectly.
> Now i have the last pb of my factory , in fact i have several create method in 
> my factory let say
>
> struct FactY
> {
> 	static std::auto_ptr<X> create() { return std::auto_ptr<X>( new Y
> () ) ;}
> 	static std::auto_ptr<X> create(int a, int b) { return std::auto_ptr<X>
> ( new Y() ) ;}
> };
>
> BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(FactY_create, create, 2, 2)
>
>
> BOOST_PYTHON_MODULE(hello)
> {
> 	class_<FactY>("FactY",no_init)
> 		.def("create",&FactY::create,FactY_create(args("x","y")) )
                      ^^^^^^^^^^^^^^

At least this is a problem.  You need to specify which overload you
mean.  In this case any type with the appropriate signature will do,
so

 		.def("create", (std::auto_ptr<X>(*)(int,int))0,FactY_create(args("x","y")) )


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




More information about the Cplusplus-sig mailing list