bobber205
bobber205

Reputation: 13372

Adding to a Memory Address Error

This doesn't compile in VSC++ 2008.

void* toSendMemory2 = toSendMemory + 4;

I am at a loss at why, though I am sure it's very stupid of me. :P

Upvotes: 2

Views: 611

Answers (2)

Jeremy Friesner
Jeremy Friesner

Reputation: 73081

You can't do pointer arithmetic on void pointers. Try casting (toSendMemory) to a (char *) first (assuming you want to add 4 bytes to it).

Upvotes: 2

fbrereto
fbrereto

Reputation: 35925

When you add N to a T* the pointer will be incremented by sizeof(T) * N bytes. sizeof(void) is nonsensical, so pointer arithmetic over void* is not allowed.

Upvotes: 11

Related Questions