User forums > Help

Pointer arithmetic - casting pointer to other type


I'm new to C++ and this language seems to be a little bit vague for me.

Please explain, for what reason I should use such code

--- Code: ---void* Src;
  t* TempSrc = (t*)Src;
  Src = (void*)TempSrc;

--- End code ---
instead of just

--- Code: ---  void* Src;

--- End code ---

In second case compiler complains about incrementing void pointer, so I assume, that pointer casting doesn't work. And in case of ((t*)Src)++ compiler complains about lvalue.

Miguel Gimenez:
Programming questions are OT here.

Ok, seems to be fixed via following trick:

--- Code: ---Src = (void*)((t*)Src + 1);

--- End code ---


[0] Message Index

Go to full version