C++11のasyncを使って非同期処理をしたいのですが、コンパイルエラーとなり上手くいきません。
おそらく初歩的な所でミスをしていると感じているのですが、STLのエラー文が私には分かり辛くて困っています。
どなたか解決策を教えて頂けますでしょうか。
#環境
Raspberry Pi 2 Model B
$uname -a
Linux rpi01 4.1.7-v7+ #817 SMP PREEMPT Sat Sep 19 15:32:00 BST 2015 armv7l GNU/Linux
$gcc -v
組み込み spec を使用しています。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/armv7l-unknown-linux-gnueabihf/5.2.0/lto-wrapper
ターゲット: armv7l-unknown-linux-gnueabihf
configure 設定: ../configure --with-fpu=vfp --with-float=hard --disable-bootstrap --enable-languages=c,c++
スレッドモデル: posix
gcc バージョン 5.2.0 (GCC)
#ソース
lang
1#include <functional> 2#include <future> 3 4using namespace std; 5struct A 6{ 7 … 8 vector<future<int>> async_result; 9 … 10}
この宣言をするだけでエラーが出ます。
コンパイル時のオプションに、-std=c++11 -lpthread は付けています。
asyncで処理させる関数の戻り値を得たい為、future<int>としています。
#エラー文
In file included from /usr/local/include/c++/5.2.0/vector:64:0, from /usr/local/include/c++/5.2.0/bits/random.h:34, from /usr/local/include/c++/5.2.0/random:49, from /usr/local/include/c++/5.2.0/bits/stl_algo.h:66, from /usr/local/include/c++/5.2.0/algorithm:62, from /usr/local/include/opencv2/hal/defs.h:572, from /usr/local/include/opencv2/core/cvdef.h:59, from /usr/local/include/opencv2/core.hpp:52, from /usr/local/include/opencv2/core/core.hpp:48, from mymonitor_main.cpp:9: /usr/local/include/c++/5.2.0/bits/stl_vector.h: In instantiation of ‘std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::future<int>; _Alloc = std::allocator<std::future<int> >]’: /usr/local/include/c++/5.2.0/bits/stl_vector.h:257:15: required from ‘std::vector<_Tp, _Alloc>::vector() [with _Tp = std::future<int>; _Alloc = std::allocator<std::future<int> >]’ mymonitor_main.cpp:86:8: required from here /usr/local/include/c++/5.2.0/bits/stl_vector.h:161:9: エラー: invalid use of incomplete type ‘class std::future<int>’ - this->_M_impl._M_start); } ^ In file included from mymonitor_main.cpp:78:0: /usr/local/include/c++/5.2.0/future:115:11: 備考: declaration of ‘class std::future<int>’ class future; ^ In file included from /usr/local/include/c++/5.2.0/bits/stl_tempbuf.h:60:0, from /usr/local/include/c++/5.2.0/bits/stl_algo.h:62, from /usr/local/include/c++/5.2.0/algorithm:62, from /usr/local/include/opencv2/hal/defs.h:572, from /usr/local/include/opencv2/core/cvdef.h:59, from /usr/local/include/opencv2/core.hpp:52, from /usr/local/include/opencv2/core/core.hpp:48, from mymonitor_main.cpp:9: /usr/local/include/c++/5.2.0/bits/stl_construct.h: In instantiation of ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = std::future<int>*]’: /usr/local/include/c++/5.2.0/bits/stl_construct.h:151:15: required from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_Tp>&) [with _ForwardIterator = std::future<int>*; _Tp = std::future<int>]’ /usr/local/include/c++/5.2.0/bits/stl_vector.h:424:22: required from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = std::future<int>; _Alloc = std::allocator<std::future<int> >]’ mymonitor_main.cpp:86:8: required from here /usr/local/include/c++/5.2.0/bits/stl_construct.h:127:11: エラー: invalid use of incomplete type ‘std::iterator_traits<std::future<int>*>::value_type {aka class std::future<int>}’ __destroy(__first, __last); ^ In file included from mymonitor_main.cpp:78:0: /usr/local/include/c++/5.2.0/future:115:11: 備考: declaration of ‘std::iterator_traits<std::future<int>*>::value_type {aka class std::future<int>}’ class future; ^
宜しくお願い致します。
2016/01/25
事態が進展した為、情報を追加します。
実際のソースコードでは、
lang
1#include <functional> 2#include <future> 3#include <vector> 4 5using namespace std; 6struct A 7{ 8 vector<future<int>> async_result; 9}; 10 11int main() 12{ 13 A* p = new A; 14 delete p; 15 return 0; 16}
の様に、構造体を動的確保しております。
テストプログラムをこの様に変更した所、上記同様のエラーが発生します。
エラー文からインスタンス化あたりでおかしな事になっているのだろうと見当をつけた所、
それが当たりでした。
しかし、なぜこれがコンパイルエラーになるのか分かりません。
どなたか教えて頂けますでしょうか。

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/24 00:44
2016/01/24 03:29