I am testing some pointers in c++. My code looks like this:
#include <iostream>
#include <vector>
using namespace std;
vector <int>& vec_return(){
vector<int> test_vec;
test_vec.push_back(1);
test_vec.push_back(2);
test_vec.push_back(3);
test_vec.push_back(4);
test_vec.push_back(5);
return test_vec;
}
int main(){
vector <int>& test_vec = vec_return();
for(int i = 0; i < test_vec.size(); i++){
cout<<test_vec[i];
}
return 0;
}
I am thinking the vec_return() function should return the pointer of a test_vec and then in main it should be printed but instead it doesn't do anything. Any suggestions?