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

Werner Joergensen wjoergensen at yahoo.com
Mon Jun 8 12:28:28 CEST 2009


Hello,
the Py++ documentation has several recommendations how to solve registration order problems with member functions.
Like for example this solution (from the documentation):
>s2 = mb.class_( "S2" )
>s2.member_function( "do_smth" ).use_overload_macro = True

But what to do if the class constructors have a registration order problem? I tried
>test = mb.class_( "Test" )
>for c in test.constructors():
>  c.use_overload_macro = True
but this doesn't solve the problem described below.

The (condensed) code I want to pythonify is:
--------------------
#include <string>
#include <iostream>
class Test:public std::string{
public:
  Test(std::string);
  Test(char*);
  Test(char);
  void printme();
};
Test::Test(std::string s):std::string(s){
}
Test::Test(char *s):std::string(s){
}
Test::Test(char c):std::string(1,c){
}
void Test::printme(){
  std::cout<<*this<<std::endl;
}
--------------------

However, a test of the generated python module shows:
>In [1]: import testmodule
>In [2]: t=testmodule.Test("Hello")
>In [3]: t.printme()
>H                                              #(expected "Hello" here)

This indicated that the Test(char) constructor is applied although a string was given.
How can I solve the problem? If possible only with module builder functions, without changes to the C code?

Thanks
Werner



      


More information about the Cplusplus-sig mailing list