- 292 名前:デフォルトの名無しさん mailto:sage [2008/01/29(火) 22:58:38 ]
- ミスって途中送信してる・・・。
こっちが本物。 #include <iostream> struct Base { int x; }; struct Derived1 : public Base { int n; }; struct Derived2 : public Base { int n, m; }; template <size_t x, size_t y> struct size_t_max { static const size_t value = x > y ? x : y; }; struct AllocUnit { static const size_t size = size_t_max<sizeof (Derived1), sizeof (Derived2)>::value; char buf[size]; }; int main(){ std::cout << AllocUnit::size << std::endl; } 基底クラスより派生クラスの方がサイズ大きいの分かってるから 2つの比較だけでいいべ。
|

|