草庐IT

swig-template

全部标签

c++ - 使用 SWIG (AIX 5.1) 从 Perl 调用 C++ 库时崩溃

我正在尝试从AIX5.1机器上的Perl调用C++库。我已经创建了一个非常简单的测试项目来尝试练习这个。我的C++共享库(test.cpp):#include#includevoidmyfunc(){printf("inmyfunc()\n");std::cout我的SWIG接口(interface)文件(test.i):%moduletest%{voidmyfunc();%}voidmyfunc();然后我像这样构建共享对象:swig-c++-perltest.ig++-ctest_wrap.cxx-I/usr/opt/perl5/lib/5.6.0/aix/CORE-otest_w

c++ - 如何将用 swig 包装的 c++ 类的实例推送到 lua 堆栈上?

我有一个用swig包装并用lua注册的类。我可以在lua脚本中创建此类的实例,一切正常。但是假设我在我的C++代码中创建了一个类的实例,并调用了新的X,并且我有lalua_stateL,其中有一个我想调用的函数,它接受一个参数,一个X的实例...我该如何调用该函数。这是(一些)有问题的代码(我省略了错误处理的东西):主要.cppclassGuiInst;extern"C"{intluaopen_engine(lua_State*L);}intmain(){GuiInstgui=newGuiInst;lua_State*L=luaL_newstate();luaopen_engine(L

c++ - Swig:如何包装 double&(double 通过引用传递)?

我正在使用SWIG从Python访问C++代码。我如何优雅地包装一个函数,该函数返回通过引用传递的变量中的值voidset(double&a){a=42.;}我不知道该怎么做。在最好的情况下,我将能够在Python中使用带有Pythonfloat的函数:>>>b=2.>>>set(b)>>>printb42.0目前它给了我一个TypeError:inmethod'TestDouble_set',argument2oftype'double&'。 最佳答案 这样做:你的swig接口(interface)文件:%include%appl

c++ - "Name The Template Parameter"奇定义

template//whyisboolhere,classbooltype=bool.Aretheyequivalent?structif_{typedeftypenamettype;};templatestructif_//whatdoesthemean?{typedeftypenameutype;};代码来自一篇名为“命名模板参数”的文章。我无法理解both结构的定义。 最佳答案 编辑:首先移动最重要的部分:if_::type;//thisisintif_::type;//thisisdouble这很方便地定义了一个可以在编译时

c++ - 专门化成员 S::display 需要 ‘template<>’ 语法

我正在创建一个特征类来帮助我的程序。我有一个名为operations的模板类包含方法display和area.当我定义这些函数时,我得到了错误。他们在这里:error:specializingmember‘traits::operations::display’requires‘template’syntaxerror:specializingmember‘traits::operations::area’requires‘template’syntax如您所见,编译器要我插入template就在这些定义之前。但是当我这样做时,我会收到一大页错误。出了什么问题,我该如何解决?这是我的程

c++ - 使用 swig 使 C++ 类看起来像一个 numpy 数组

什么是公开C++类的好方法,该类提供与numpy(scipy)一起使用的类数组接口(interface)?我所说的类似数组的接口(interface)是指://file:Arr.hclassArr{public:intn_rows;intn_cols;float*m_data;Arr(intr,intc,floatv);virtual~Arr();floatget(inti,intj);voidset(inti,intj,floatv);longdata_addr(){return(long)(m_data);}};约束:我只关心将其基础数据存储为连续平面数组的类,该类将提供对原始存储

c++ - 在类型说明符中使用 "simple-template-id"

在C++11标准中,dcl.type.simple和dcl.type.elab部分声明类型说明符可以包括simple-template-编号。另一方面,根据temp.names部分,simple-template-id可以表示函数模板特化。真的可以使用函数模板特化来指定类型吗? 最佳答案 7.1.6.2/2Theothersimple-type-specifiersspecifyeitherapreviously-declareduser-definedtypeoroneofthefundamentaltypes(3.9.1).强调

c++ - 为什么bitset要用template来实现?

要定义一个16位的位集,就像这样:std::bitsetbs(0x123);如果让我设计一个bitset类,我大概会这样:mine::bitsetbs(16,0x123);std::bitset是由模板实现的有什么原因吗?这是我们应该在某些情况下应用的好模式吗? 最佳答案 Isthereanyreasonthatstd::bitsetisimplementedbytemplate?Isthisagoodpatternthatweshouldapplyinsomesituations?因为std::bitset被设计成一个静态位集。在

c++ - 错误 : Use of class template requires template argument list

当我尝试运行我的程序时,此错误显示为“errorC2955:'FOURTEEN':useofclasstemplaterequirestemplateargumentlist”#includeusingnamespacestd;templateclassFOURTEEN{private:Ta[n];public:voidReadData();voidDisplayData();};voidFOURTEEN::ReadData(){for(inti=0;i>a.[i];}voidFOURTEEN::DisplayData(){for(inti=0;i>a.[i]P;//Readdatai

python - swig:扩展类模板以提供 __str__

假设你有一个模板类Foo,你想用Swig透明地包装它以便打印类:>>>fromexampleimport*>>>f=Foo2()>>>print(f)InFooclass!我关注了thispost和thisone.所以我的头文件是:#includetemplateclassFoo{public:friendstd::ostream&operator还有我的界面文件:%{#include#include#include"foo.hpp"%}%include"std_iostream.i"//Trygrabbingitunmodified%include"foo.hpp"/*Instant