You are not logged in.
I'm giving a shot to SIP to try to get Python bindings for a C++ test class. The class is very simple, and has two overloaded constructors:
class AnotherConcreteAlgorithm {
public:
AnotherConcreteAlgorithm(const char *name, double doubleProp);
AnotherConcreteAlgorithm(const char *name, int intProp);
~AnotherConcreteAlgorithm();
bool Initialize();
bool Process();
bool Finalize();
const char *GetType() const;
const char *GetVersion() const;
const char *GetParams() const;
const char *GetName(){
return _name;
}
private:
double _doubleProp;
int _intProp;
const char *_name;
};
I wrote a .sip file to wrap it as:
%Module Concrete
class AnotherConcreteAlgorithm {
%TypeHeaderCode
#include "AnotherConcreteAlgorithm.h"
%End
public:
AnotherConcreteAlgorithm(const char *name, double doubleProp);
AnotherConcreteAlgorithm(const char *name, int intProp);
~AnotherConcreteAlgorithm();
bool Initialize();
bool Process();
bool Finalize();
const char *GetType() const;
const char *GetVersion() const;
const char *GetParams() const;
};
Now, when I try to wrap it I get:
$ sip -c . Concrete.sip
sip: AnotherConcreteAlgorithm has ctors with the same Python signature
So it seems that SIP does not allow overloading a constructor with an int and a double signature. I've done it before without problems using boost.python, so I think that it's generally feasible and that maybe I'm making some mistake with SIP. I've found no useful report on the web about this problem, most of them are PyQt related and are not very helpful. So I think I'm making a very basic mistake, something that no one is so noob to do and thus almost no report on this is available. Still, I can't work it out by myself; is there anyone who can help me, please? Thanks.
Last edited by snack (2013-05-08 12:23:17)
Offline
I found the solution. Because of some automatic type conversion you have to tell SIP to maintain the signature using the /Constrained/ construct in the .sip file for the double overload, e.g.:
AnotherConcreteAlgorithm(const char *name, double doubleProp /Constrained/);
With this trick SIP runs smoothly. The wrapped class only works for python2.7, while trying to wrap with python3.3 I get:
>>> from Concrete import *
>>> c = AnotherConcreteAlgorithm("hello", 1.)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: AnotherConcreteAlgorithm(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'str'
overload 2: argument 1 has unexpected type 'str'
overload 3: argument 1 has unexpected type 'str'
Anyway, this is another topic and maybe I'll open another thread...
Offline