Quote: In general, you can increment and decrement temporary iterators. However, for vectors and strings, you typically can't. For all fundamental data types, such as pointers, you are not allowed to modify temporary values.
Can anyone explain this line?
Can anyone explain what the second line means? Not sure what the author is talking about by "temporary values"
basicly he's trying to tell you that for fundamental types
isn't allowed :D
T t;(t + x) = y;
isn't allowed :D
Well, here is an example of a temp value, and where you can't modify it...
#include<iostream>void f(char *s){ s[1] = 'X'; // <--- WATCH THIS...}int main(){ char buf[5] = "test"; f(buf); // THIS IS LEGAL (passing in address to a 'real' object) f("test"); // THIS IS NOT ... test becomes a temp var, and changing it will // crash the app return 0;}
Why wasnt vector implemented so that it could support ++ with temporary values? Would it cause poor performance or were the writers of the vector class just lazy?
Quote:Original post by Gink
Why wasnt vector implemented so that it could support ++ with temporary values? Would it cause poor performance or were the writers of the vector class just lazy?
the 'typical' vector/string iterator is a bald pointer i.e. typicly you have
//templated etcclass vector{//loads of stuff typedef value_type *iterator; iterator begin(){/*etc*/}};
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement