Here's some test code to show how I would do it... yet there's something wrong.
#include <vector>
#include <iostream>
using namespace std;
void function (vector<int> *Test){
Test->push_back(2);
}
int main(void){
vector<int> test;
int *testPointer;
testPointer = &test;
test.push_back(1);
function(testPointer);
test.push_back(3);
for (int i=0; i<test.size(); i++){
cout << "test[" << i << "] = " << test[i] << "\n";
}
return 0;
}
Target output: test[0] = 1 test[1] = 2 test[2] = 3
What modifications would be made to the code, in order to get this desired output? At the moment it's not even compiling:
Visual C++ 2008 Express Edition said:
testPointer = &test;
- cannot convert from 'std::vector<_Ty> *' to 'int *'
- cannot convert from 'std::vector<_Ty> *' to 'int *'


Sign In
Create Account

Back to top









