[C++-sig] [Py++] registration order problem in constructor

Werner Joergensen wjoergensen at yahoo.com
Tue Jun 9 20:22:45 CEST 2009


Dear Roman,
thank you very much for the suggested workaround. Could you answer the additional questions below?

...
> > This indicated that the Test(char) constructor is applied although a string 

> was given.
> > How can I solve the problem?
> 
> Py++ doesn't help you here.
> 
> > If possible only with module builder functions, without changes to the C code?
> 
> Partially. I suggest you to add few free functions and expose them:
> 
> Test* create_test_from_char( char ){...}
> Test* create_test_from_string( std::string ){...}
> Test* create_test_from_char_array( const char* ){...}
> 
> Thus you will not have to change your original code and the user code
> will be more "readable".
> There are few other alternatives, but I think you've got the idea.

Yes, with your suggestion I can at least work with the code.

But would you mind mentioning the other alternatives? My aim is to construct the class like the "t=testmodule.Test("Hello")" above.
I was not able to use the suggested "create_*" functions as fake constructors "test.add_fake_constructors( mb.calldefs( 'create_test_from_char' ) )". Do they have to return an auto_ptr<Test> for this purpose?

Thank you
Werner



      


More information about the Cplusplus-sig mailing list