[英]How can I export vector<T>::push_back to Python?
這個問題很簡單,我會誤解一些瑣碎的東西。 但是由於我幾個小時都找不到解決方案,請在這里讓我問一個問題。
我想做的是使用Boost.Python將std::vector<T>
容器類的push_back
方法(帶有一些固定類型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
選項和Boost.Python v1.56.0的clang ++。
謝謝。
在我看來,問題在於C ++ 11中有兩個版本的push_back 。 嘗試這樣做
static_cast<void (vector_double::*)(const double&)>(&vector_double::push_back);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.