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 to the true type of the object.
So unless it is dereferenced to an unrelated type, it's ok with the strict aliasing rule ?
Aucun commentaire:
Enregistrer un commentaire