I need to access an object in a buffer, pointed by a void pointer. The object is located at a certain offset but since arithmetic on a void pointer is prohibited how can I access the object?
You can cast the pointer to char*
(+1 on such pointer is offset by one byte) or any other pointer type if that suits your needs better.
However, this approach is grossly error prone! You better check your design, something smells here! void*
are in 99% of cases unnecessary in C++, designs that use them are usually more "C" than "C++". Remember, templates and inheritance should be the way to do these things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With