swig没有重载的匹配功能 [英] swig no matching function for overloaded

查看:234
本文介绍了swig没有重载的匹配功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用SWIG包装我的c ++代码时遇到了问题:
我在C ++中有一个类,声明如下:

  int hexDump(string& dmpstr,bool space = true)const; 

我在接口文件中加入了std_string.i,我可以很好地传递字符串参数。
,但是当我在我的PHP代码中调用我的方法时,如下所示:

  $ bf-> hexDump('12 ',真正); 

我得到这个错误:

 致命错误:重载的'PKI_Buf_hexDump'

没有匹配的函数PKI_Buf是我班的名字。
的任何想法??

解决方案

这里的问题似乎是缺少非常量字符串引用的类型检查因此在重载决议期间,SWIG拒绝真正适合呼叫的人。



您可以通过添加您自己的类型检查来解决它,我举了一个例子:

 %模块测试

%include< std_string.i>

%typemap(typecheck,precedence = 141)std :: string& str {
$ 1 = Z_TYPE_PP($ input)== IS_STRING;
}

%{
#include< iostream>
%}

%inline%{
void func(std :: string& str,bool b = false){$ b $ std :: cout<< 在C ++中:<< str<< \\\
;
str =output;
}
%}

我不太确定正确的<一个href =http://www.swig.org/Doc1.3/Typemaps.html#Typemaps_overloading =nofollow>优先值。我选择了141,因为这使得它低于默认字符串值。



我检查了一切正确的工作:

 <?php 
include('test.php');
回显testing\\\
;
$ str =input;
test :: func($ str,true);
回声在PHP中:。 $ str。 \\\
;
?>

按预期工作。

我认为事实上,这种类型的类型检测默认不起作用,因为它使用的类型检测将无法工作。你可能想在邮件列表中提出这个问题。


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 space=true)const;

also I include std_string.i in my interface file and I can pass string arguments well. but when I call my method in my PHP code as below:

$bf->hexDump('12',true);

I got this error:

Fatal error: No matching function for overloaded 'PKI_Buf_hexDump'

PKI_Buf is the name of my class. any idea??

解决方案

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 <std_string.i>

%typemap(typecheck,precedence=141) std::string& str {
  $1 = Z_TYPE_PP($input) == IS_STRING;
}

%{
#include <iostream>
%}

%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:

<?php
include('test.php');
echo "testing\n";
$str = "input";
test::func($str, true);
echo "In PHP: " . $str . "\n";
?>

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.

这篇关于swig没有重载的匹配功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆