开发者

Adding to a Memory Address Error

开发者 https://www.devze.com 2022-12-21 17:44 出处:网络
This doesn\'t compile in VSC++ 2008. void* toSendMemory2 = toSendMemory + 4; I am at a loss 开发者_StackOverflow中文版at why, though I am sure it\'s very stupid of me. :PWhen you add N to a T* the

This doesn't compile in VSC++ 2008.

void* toSendMemory2 = toSendMemory + 4;

I am at a loss 开发者_StackOverflow中文版at why, though I am sure it's very stupid of me. :P


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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号