1
假設我有一個類A
:這是定義
class A : virtual SomeOtherClass{
//Stuff here
};
假設我有這樣做的地方:
A thing;
alignas(A) uint8_t arr[sizeof(A)];
for (int x = 0; x < sizeof(A); x++)
{
//Copy into array
arr[x] = reinterpret_cast<uint8_t*>(&A)[x];
}
A* otherThing = reinterpret_cast<A*>(arr);
是我在做什麼這裏定義的行爲,還是我殺我自己好歹我不知道?
'reinterpret_cast'幾乎總是一個壞主意。 –