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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.