如何为std :: pair<>创建界面在swig和Python中没有默认构造函数? [英] How do I make interface for std::pair<> with no default constructor in swig and Python?

查看:86
本文介绍了如何为std :: pair<>创建界面在swig和Python中没有默认构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我要实现std :: pair< T,U>在swig& python中。

T是类,它没有默认构造函数。

当我通过swig创建wrapper.cxx时,它有一个编译错误

Hi all,
I'm going to implement std::pair<T, U> in swig&python.
T is class and it doesn't have default constructor.
When I make wrapper.cxx via swig, it has a compile error that

error C2512: 'T' : no appropriate default constructor available



这是因为当创建std :: pair变量时,它叫做T和U的施工人员。



如何解决?



什么我试过了:



我试图在此之后添加代码:




It occurs because when create std::pair variable, it calls constructors of T and U.

How can I fix it?

What I have tried:

I have tried to add code following this:

%feature("valuewrapper") std::pair<T, U>;
%ignore std::pair<T, U>::pair();



但它没有效果。


But it has no effect.

推荐答案

我不知道 swig 但你得到了一个C ++编译错误。



T U 是必须用现有类类型替换的模板参数。

C ++示例:

I don't know swig but you got a C++ compiler error.

T and U are template parameters that must be replaced with existing class types.
C++ Examples:
std::pair <int, int> p1;
std::pair <int, std::string> p2;

另请参阅 pair :: pair - C ++ Reference [ ^ ]。



所以你必须根据 std :: pair 使用的类型进行相应的使用(猜测):

See also pair::pair - C++ Reference[^].

So you have to use it accordingly depending on the types used with std::pair (guessed):

%feature("valuewrapper") std::pair <int, int>;
%ignore std::pair<int, int>::pair();

%feature("valuewrapper") std::pair <int, std::string>;
%ignore std::pair<int, std::string>::pair();


这篇关于如何为std :: pair&lt;&gt;创建界面在swig和Python中没有默认构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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