y‰SŽÒнŒ}zC/C++Ž ..
[2ch|¥Menu]
229:222
07/10/03 22:19:01
#include <cassert>

template <typename Derived>
struct base
{
@@char interface() { return reinterpret_cast<Derived*>(this)->implementation(); }
@@static char static_func() { return Derived::static_sub_func(); }
};

struct derived : base<derived>
{
@@char implementation() { return 'A'; }
@@static char static_func() { return 'B'; }
};

template <typename T>
char f(base<T>& t) { return t.interface(); }

int main() {
@@derived d;
@@assert( f(d) == 'A' );
}
‰pŒê”Åwikipedia‚ðŽQl‚É‘‚¢‚Ă݂܂µ‚½‚ª‚Ü‚¾‚µ‚Á‚­‚è‚«‚Ü‚¹‚ñ
‚Æ‚¢‚¤‚©‚ ‚«‚ç‚©‚ɈႤ‚悤‚È‹C‚ª‚µ‚Ü‚·


ŽŸƒy[ƒW
‘±‚«‚ð•\ަ
1‚ð•\ަ
ÅVƒŒƒX•\ަ
ƒXƒŒƒbƒh‚ÌŒŸõ
—ÞŽ—ƒXƒŒˆê——
˜b‘è‚̃jƒ…[ƒX
‚¨‚Ü‚©‚¹ƒŠƒXƒg
¥ƒIƒvƒVƒ‡ƒ“‚ð•\ަ
‰É‚‚Ԃµ2ch

4995“ú‘O‚ÉXV/84 KB
’S“–:undef