deftemp02.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 29 行

C
29
字号
// 14.1p13: "The scope of a template-parameter extends from its point of
// declaration until the end of its template. In particular, a template-
// parameter can be used in the declaration of subsequent template-
// parameters and their default arguments."

#include "fail.h"

template< class T, class U = T>
struct A {
    T member1;
    U member2;
};

template< class T, int n = sizeof( T ) >
struct B {
    static const int val = n;
};

int main()
{
    A<int> a;
    if( sizeof( a.member1 ) != sizeof( a.member2 ) ) fail(__LINE__);

    B<int> b;
    if( sizeof( int ) != b.val ) fail(__LINE__);

    _PASS;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?