When using cppcheck on my code it indicated a function could be made const. Cppcheck seems to be correct but I found the memcpy in the code strange.
Excerpt from the code:
if ( (offset + size) <= _bufferSize )
{
char* _destPtr = (char*)_buffer + offset;
memcpy(_destPtr, data, size);
result = true;
}
To my understanding the memcpy will indirectly write to _buffer so the function is not const. However even when using _buffer directly the compiler still compiles the code without an error.
Why does the compiler not generate an error here?