忽略运算符<<在swig界面
Ignore redefinition of operator<< in swig interface
我在不同的名称空间中有两个版本的operator<<
,它们具有相同的签名。由于swig
将它们压缩到一个名称空间中,它们彼此冲突,从而阻止我运行接口。
我不需要使用脚本语言(Python)中的流插入操作符,有没有办法抑制这些。
%ignore
指令似乎没有帮助。
最小测试设置
头文件//file:test.h
#include <iostream>
#include <boost/numeric/ublas/vector.hpp>
namespace probabilities{
typedef boost::numeric::ublas::vector< double > UnivariateTable;
inline
std::ostream& operator<<( std::ostream& ostr, const UnivariateTable& table){
ostr<<"I am a table";
return ostr;
}
}
namespace positions{
typedef boost::numeric::ublas::vector< double > PositionVector;
inline
std::ostream& operator<<(std::ostream& ostr, const PositionVector& vect){
ostr<<"I am a vector";
return ostr;
}
}
Swig接口文件
//file:test.i
%module test
%{
#include "test.h"
%}
%ignore operator<<;
%include "test.h"
结果[dmcnamara]$ swig -c++ -python -I/opt/vista_deps/include -I/opt/vista/include test.i
test.h:26: Error: '__lshift__' is multiply defined in the generated target language module in scope .
test.h:15: Error: Previous declaration of '__lshift__'
在写问题的过程中,我意识到了答案:
您需要为%ignore
指令指定名称空间:
%ignore positions::operator<<
%ignore probabilities::operator<<
您也可以使用预处理工具:
//file:test.h
#include <iostream>
#include <boost/numeric/ublas/vector.hpp>
namespace probabilities{
typedef boost::numeric::ublas::vector< double > UnivariateTable;
#ifndef SWIG
inline
std::ostream& operator<<( std::ostream& ostr, const UnivariateTable& table){
ostr<<"I am a table";
return ostr;
}
#endif
}
namespace positions{
typedef boost::numeric::ublas::vector< double > PositionVector;
#ifndef SWIG
inline
std::ostream& operator<<(std::ostream& ostr, const PositionVector& vect){
ostr<<"I am a vector";
return ostr;
}
#endif
}
相关文章:
- Python 3.7 和 excess_args 的 SWIG 问题
- 从具有默认值的部分指定模板类继承时发生SWIG错误,具有不带默认值的正向声明
- 为重写std::exception的库生成swig接口时出错
- 元组由 Swig 生成的 Python 包装器返回,用于C++向量
- 无法使用 SWIG 在 Python 中实例化C++类(获取属性错误)
- SWIG Java 在使用 -DSWIGWORDSIZE64 时将int64_t转换为 jlong
- 使用 SWIG 更改生成的 CS 函数中的返回类型
- 在模板化函数中重新定义(忽略)的 SWIG 标识符
- 使用 swig 追加到字节数组
- Qt5 用户界面编译器:-i 选项不可用
- 如何使用 swig 修改类构造函数以保留对其中一个构造函数参数的引用?
- Java SWIG wrapper vs direct function calling
- 如何使用VirtualDesktopManager界面?
- <string> 如何在使用 SWIG 时将 int 数组和 List 作为参数传递给 C# C++
- 类型为 'std::map< char,int > 的 <Swig 对象的代理
- 使用SWIG从C++回调到C#
- 如何使用谷歌基准测试对自定义界面进行基准测试
- Swig:处理简化界面的最佳方式
- Swig 界面中的类型映射错误
- 忽略运算符<<在swig界面