I am trying to write a function that will convert a generic list to a vector, however, I cannot get my function to compile. Here is my code (which sits in a .h file):
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;
}
Can anybody point out what I am missing here?
The compiler error is the following:
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> > > >?
1 Answer