1
I’d like to pass one std::list
temporary to a function, but do not know if it is possible to do it. I know it is possible to pass a std::vector
temporary with a initializer_list
:
#include <iostream>
#include <vector>
template<typename T>
void mostra(const std::vector<T>& myVec)
{
for(T var : myVec)
std::cout << var << "\n";
}
int main()
{
mostra<int>({12, 14, 28, 7, 10});
return 0;
}
Always good to give a test :)
– Lucas Virgili
Exactly, when the function ends the lists go out of scope. And no need to apologize XD
– Lucas Virgili
No, for that already has the stackoverflow.com normal.
– Lucas Virgili