how do I get the value of 'a' from the vector ?
edit:Code:int a = 5, *b = &a; vector<int*> v; v.push_back(b); cout << ?
found how:
*v[0]
how do I get the value of 'a' from the vector ?
edit:Code:int a = 5, *b = &a; vector<int*> v; v.push_back(b); cout << ?
found how:
*v[0]
Last edited by jaymz; 10-12-2011 at 05:24 PM.
Why not store integers in the vector instead of pointers to integers?
I agree with you. I would totally avoid using pointers in this case, but unfortunately I am forced to
Now I discovered another inconvenience of doing this. I am now pushing more values into it. While iterating through this vector, it only prints out the last value pushed for each v[i] vector position. How to fix this ? Maybe I'm not pushing correctly and my vector has the same (last pushed) value all over ?
Putting the address of a local variable inside a container of pointers, is a huge red flag.
Show us some code and we'll work out how you should be doing it.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"