swig no matching function for overloaded

前端 未结 1 1196
孤街浪徒
孤街浪徒 2021-01-16 06:45

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          


        
1条回答
  •  -上瘾入骨i
    2021-01-16 07:03

    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.

    0 讨论(0)
提交回复
热议问题