I'm trying to make a function that takes a void*
, copies some memory to it, and then moves the pointer.
Since it is a void pointer, I thought I'd cast it to char*
and move that, like so:
PVOID SendAndMoveHead(PVOID dest, const Message& message, const size_t& size)
{
PVOID ret = CopyMemory(dest, (PVOID)message.msg.c_str(), size);
((char*)dest) += size;
return ret;
}
However, VS complains about ((char*)dest)
saying
expression must me a modifiable lvalue
which I thought it was, since the following works:
PVOID SendAndMoveHead(PVOID dest, const Message& message, const size_t& size)
{
PVOID ret = CopyMemory(dest, (PVOID)message.msg.c_str(), size);
char* d = (char*)dest;
d += size;
return (PVOID)d;
}
If someone could shed some light on why the first version shouldnt work I'd really appreciate it.