struct Test { void doAction() {} }; // Create and save into a void* void *ptr = new Test; // Real use through a Test* Test *t = static_cast<Test *>(ptr); t->doAction(); // Delete delete static_cast<Test *>(ptr);
ptr is used only to save the address of the object, and the address is only dereferenced by the true type of the object.
So, if it is not dereferenced by an unrelated type, is it okay with the strict rule of aliases?
, /. void*, (, , static_cast, void* , , , , ).
void*
static_cast
, . , t static_cast<T*> , , .
t
static_cast<T*>