Say i have code like below:
Code:
vector<int> test;
test.push_back(1);
test.push_back(2);
for(size_t i = 0; i < test.size(); ++i)
cout << test[i] << endl;
Which prints out:
1
2
Ok no problem. But if i change it so i have a pointer to a vector of int's like this:
Code:
vector<int> *test;
test->push_back(1);
test->push_back(2);
for(size_t i = 0; i < test->size(); ++i)
cout << test[i] << endl;
I get this error:
Code:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion) d:\school\comp446\project\genalib\genalib.cpp 18
So how would i use the [] operator of the vector stl templates when i use a pointer to a vector or int's? Would i have to use test->at(i)? It works if i do that but im just wondering if i can use the [] operator or not.