c++ - What does "*ptrInt ++" do? -


i'm implementing template pointer wrapper similar in functionaltiy boost::shared_ptr.

i have pointer integer ptrint.

what want do: increment integer ptrint points to.

my initial code this: *ptrint ++;, although tried same using (*ptrint) ++;

apparently, however, this doesn't seem expected to. in end got working using *ptrint += 1;, i'm asking myself:

  • what *ptrint ++; do?
  • is there more elegant solution using *ptrint += 1;?

*p++    // return value of object p points , increment pointer (*p)++  // above, increment object afterwards, not pointer *p += 1 // add 1 object p points 

the final 2 both increment object, i'm not sure why didn't think worked. if expression used value, final form return value after being incremented others return value before.

x = (*p)++; // original value in x  (*p)++; x = *p;     // new value in x 

or

x = ++*p;   // increment object , store new value in x 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -