Reputation: 37
I have a void* pointer
. I want to cast the value at that pointer to an int and add it the value at another void* x
. I have already tried:
x += (int)(*pointer);
But this gives me a operand of type 'void' where arithmetic or pointer type is required
error
Upvotes: 0
Views: 2033
Reputation: 782693
You can't dereference a pointer to void. That would return a value of type void
, which doesn't exist.
You have to cast the pointer to an int*
, then dereference that.
x += *(int*)pointer;
Upvotes: 7