How can I cast a binary array to a known class?
Essentially I have a byte array of data like so:
unsigned char * buff[sizeof(MyClass)];
I'm using unsigned char for each byte as I assume it is a length of 1 byte.
How can I cast this array to what I know the data represents? I have taken the data from memory of MyClass, and put it in this buffer - now I need to cast it back to MyClass.
I've seen reinterpret_cast but I'm not sure if it would apply here.
reinterpret_cast, but why do you want to do this in the first place?unsigned char buff[sizeof(MyClass)];and doreinterpret_cast<MyClass *>(buff),buffwill end up acting like anunsigned char *.