One way would be to have a function returning a reference to a static instance:
const std::vector<int>& get_magic_vector()
{
static std::vector<int> v{3, 5, 1};
return v;
}
Then
for (auto i : get_magic_vector())
std::cout << i << " ";
2
solved c++ define vector in separate function