code error

Mar 23, 2011 at 10:26am
hi, I'm fairly new to c++. I found this generic question is a book asking to spot the error in the code, but no answer was given. this has been doing my head for a few days now:

void function(std::vector<int> v){
A* _a = new A
std::vector< int >::iterator it = v.begin();
for(; it != v.end();it++){
_a->f(*it);
}
}

any help?
Last edited on Mar 23, 2011 at 10:38am
Mar 23, 2011 at 10:29am
The compiler tells you what's wrong. If you don't understand it, you should post the error code.

It's impossible to guess what's wrong without seeing your definition of A.
Mar 23, 2011 at 10:46am
if A::f() is not a const method, your function will have no effect on the vecotr, since the vector is passed by value, so the function is run on a copy of the vector
Topic archived. No new replies allowed.