ジェネリックリストをベクターに変換する関数を作成しようとしていますが、コンパイルする関数を取得できません。以下は私のコード(.hファイルの中にあります)です:C++でベクターテンプレートを返すことができません
template <class T>
inline std::vector<T> list2vector(std::list<T> &l)
{
std::vector<T> v;
v.insert(v.begin(),l.begin(),l.end());
return v;
}
私がここで紛失しているものは誰でも指摘できますか? コンパイルエラーは次のとおりです。
find_rpeat.cpp:85: error: invalid initialization of non-const reference of type
?std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&?
from a temporary of type
?std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >?
たぶん、あなたは、関数のシグネチャで 'のconstのstd ::リスト'を必要ですか? –
arrowd
このコードは私のためにコンパイルされました[http://ideone.com/p3CEt](http://ideone.com/p3CEt) – ks1322
wow、constを追加すると、そのトリックができました。 – user788171