C++相談室 part48
■ このスレッドは過去ログ倉庫に格納されています
0140デフォルトの名無しさん
2006/03/21(火) 09:30:26よしわかった。
じゃぁまずは offsetof 使ったやつを。
C が POD 限定になるうえに offsetof(C, y.y1) が怪しいが、
とりあえず >>134 の C についてコンパイルと実行はできた。
void print(C* p)
{
static size_t const offset_to_int[4] = {
offsetof(C, x),
offsetof(C, y.y1),
offsetof(C, y.y2),
offsetof(C, z),
};
for(int i = 0; i < 4; ++i)
{
printf("%d\n", *reinterpret_cast<int*>(reinterpret_cast<char*>(p) + offset_to_int[i]));
}
}
■ このスレッドは過去ログ倉庫に格納されています