I have a problem in wrapping my c++ code in PHP with SWIG: I have a class in C++ with method which is declared as below:
int hexDump(string &dmpstr,bool
The problem here seems to be that a typecheck for non-const string references is missing and so during the overload resolution SWIG is rejecting what is really the right candidate to call.
You can work around it by adding your own typecheck, I made an example:
%module test
%include
%typemap(typecheck,precedence=141) std::string& str {
$1 = Z_TYPE_PP($input) == IS_STRING;
}
%{
#include
%}
%inline %{
void func(std::string& str, bool b=false) {
std::cout << "In C++: " << str << "\n";
str = "output";
}
%}
I'm not too sure what the right precedence value is. I picked 141 because that makes it lower than the default string value.
I checked it all works correctly with:
Which worked as expected.
I think the fact that the typecheck typemap for this doesn't work by default is a bug since the typecheck it uses will never work. You might want to raise this on the mailing lists.