Tuesday, September 19, 2006

SWIG and Overloaded Constructor

I have a class that has three constructors
class Foo {
Foo(const vector<const char *>* files, bool flag);
Foo(const char* file, bool flag);
Foo();
// ...
};
I am using typemap that maps between a list of strings and a const vector of const char*s. The typemap works fine for a function, but has trouble with the overloading. SWIG generates a wrapper function new_Foo() that dispatches based on the number and type of the arguments. The dispatch function checks for the exactly matching vector pointer using SWIG_ConvertPtr(). This check fails for the list of strings, so new_Foo() reports there is no matching constructor. The function that new_Foo() failed to call has the typemap code that converts the list of strings to the appropriate type.

What am I doing wrong?

No comments: