c++ - 错误 C2039 : 'type_name' : is not a member of of 'swig::traits<Bar>'

标签 c++ visual-c++ swig

我无法 SWIG 包装返回类实例指针映射的函数。编译生成的 SWIG 代码时出现编译错误。

error C2039: 'type_name' : is not a member of 'swig::traits<Bar>'

这是我的 .i 文件

class Foo
{ 
... 
}; 

class Bar
{
...
};

%template(MapFooPtrBarPtr) std::map<Foo*, Bar*>; 

std::map<Foo*, Bar*> GetMap();

最佳答案

将以下类型映射代码添加到 .i 文件中的 %template 之前。请注意返回字符串中类名后面缺少“*”。

%{
    namespace swig {
    template <> struct traits<Bar>
    {
        typedef pointer_category category;
        static const char* type_name()
        {
            return "Bar";
        }
    };
    }
%}

从以下位置获得解决方案:http://swig.10945.n7.nabble.com/std-containers-and-pointers-td3728.html

关于c++ - 错误 C2039 : 'type_name' : is not a member of of 'swig::traits<Bar>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38404806/

相关文章:

c++ - 具有不同定义的内联函数的不可预测的行为

c++ - 在 C++ 中定义静态常量变量

c++ - 多态性和指针数组 (C++)

c++ - 仅当设置了标志时才打开文件(稍后关闭)

c++ - Lua SWIG 基础知识

c++ - 与空项目相比,在 Visual Studio 中使用模板创建解决方案实际上有何作用?

c++ - 名称修改后如何恢复到原来的命名空间?

c++ 数组拷贝显示 vc++ 中的错误

java - 将数组作为指针+大小或范围传递给包装函数

c - SWIG 无法正确处理 64 位 c 指针