小编Dan*_*y S的帖子

SWIG包装矢量矢量(C++到python) - 如何将内部矢量识别为代理对象?

我面临着与std :: vectors,C++ SWIG Python的Wrap std :: vector类似的问题- 但它不仅仅是简单的C++解析.我的C++代码中有以下内容

namespace ns {
    typedef unsigned long long uint64_t;
    typedef std::vector<uint64_t> Vector;
    typedef std::vector<Vector> VectorOfVectors;

    class MyClass {
        /// ...

        /// Returns a reference to the internal vector allocated in C++ land
        const VectorOfVectors &GetVectors() const;
    };
}
Run Code Online (Sandbox Code Playgroud)

并在SWIG包装器中

%module myswig    
// ...
%template(Uint64V) std::vector<ns::uint64_t>;
%template(VUint64V) std::vector<std::vector<ns::uint64_t> >;
Run Code Online (Sandbox Code Playgroud)

所以包装工作正常,包括类,我可以检索类的向量向量确定:

import myswig
m = myswig.MyClass()
v = m.GetVectors()
print v
Run Code Online (Sandbox Code Playgroud)

这给了我:

<myswig.VUint64V; proxy of <Swig Object of type 'std::vector< std::vector< ns::uint64_t,std::allocator< …
Run Code Online (Sandbox Code Playgroud)

c++ python swig vector

11
推荐指数
1
解决办法
4739
查看次数

标签 统计

c++ ×1

python ×1

swig ×1

vector ×1