这个问题相当简单,我会误解一些微不足道的事情。但由于我几个小时都找不到解决方案,请让我在这里问一个问题。
我想要做的是使用Boost.Python将push_back
容器类的std::vector<T>
方法导出为一些固定类型T
(比如double
)到Python。
为此,我编写了以下代码:
typedef std::vector<double> vector_double;
class_<vector_double>("vector_double")
.def("append", &vector_double::push_back);
但是这不会编译出现以下错误:
/Users/kenta/experiments/bisite/include/bisite/conservation_score.hpp:25:7: note:
candidate constructor (the implicit default constructor) not viable:
requires 0 arguments, but 1 was provided
/Users/kenta/experiments/bisite/src/bisite/pybisite.cpp:90:10: error: no
matching member function for call to 'def'
.def("append", &vector_double::push_back);
~^~~
/usr/local/include/boost/python/class.hpp:234:11: note: candidate template
ignored: couldn't infer template argument 'F'
self& def(char const* name, F f)
^
/usr/local/include/boost/python/class.hpp:224:11: note: candidate function
template not viable: requires single argument 'visitor', but 2 arguments
were provided
self& def(def_visitor<Derived> const& visitor)
... and more candidates
类型演绎(?)似乎失败但我无法弄清楚原因。
当我将vector_double
定义为std::vector<double>
的子类时,上面的代码已成功编译。但出于某种原因我不想这样做。
你能教我解决这个问题吗?
我正在使用带有-std=c++11
选项的clang ++和Boost.Python v1.56.0。
谢谢。
答案 0 :(得分:0)
在我看来,问题是,C ++ 11中有两个版本的push_back。 尝试这样做
static_cast<void (vector_double::*)(const double&)>(&vector_double::push_back);