1

I have a function implemented in func.hpp by C++ as

void func(const std::vector<std::shared_ptr<double> > &x) {
    //something is doing here.
}

and in the swig .i file, I have added

%include <std_shared_ptr.i>
%include <std_vector.i>
%shared_ptr(DoubleValue)
%template(doublevec) std::vector<double>;
%template(doubleptrvec) std::vector<std::shared_ptr<double> >;
%{
#include "func.hpp"
}
%include "func.hpp"

When I call the function in python as

x=0.1
func([x])

I got error saying TypeError: in method 'func', argument 2 of type 'std::vector< std::shared_ptr< double >,std::allocator< std::shared_ptr< double > > >'.

I think I must do something to pass python objects as pointers to C++ function: does anyone have experience for this?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
maomiT
  • 11
  • 1
  • The type of `%shared_ptr(DoubleValue)` doesn't exist, and you can't use a primitive type (`double`) with `%shared_ptr()`. Why do you need a `vector>` and not just a `vector>`? – Mark Tolonen Jun 08 '20 at 23:57
  • it complies successfully with %shared_ptr(DoubleValue), should I use others? The idea of using vector> is to track and log some variables. – maomiT Jun 25 '20 at 14:03

0 Answers0