Can anyone explain this line?

Started by
4 comments, last by DigitalDelusion 18 years, 10 months ago
Can anyone explain what the second line means? Not sure what the author is talking about by "temporary values"
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.
Advertisement
basicly he's trying to tell you that for fundamental types
T t;(t + x) = y; 


isn't allowed :D
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
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;}
------------------------------------------------------------// TODO: Insert clever comment here.
no, actually that's an example of string literals being considred constant.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
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*/}};

HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats

This topic is closed to new replies.

Advertisement