小编Liv*_*ara的帖子

使用不完全类型显式实例化函数模板

下列:

template< typename >
struct S;

template< typename T >
S< T >& f (S< T >& s) {
    const typename S< T >::nested ignore;
    return s;
}

template S< char >& f (S< char >&);

template< typename >
struct S {
    struct nested { };
};
Run Code Online (Sandbox Code Playgroud)

用gcc编译,但不用clang编译:

$ clang -c /tmp/t.cpp
/tmp/t.cpp:6:20: error: implicit instantiation of undefined template 'S<char>'
    const typename S< T >::nested ignore;
                   ^
/tmp/t.cpp:10:21: note: in instantiation of function template specialization 'f<char>' requested here
template S< …
Run Code Online (Sandbox Code Playgroud)

c++ templates

5
推荐指数
1
解决办法
521
查看次数

标签 统计

c++ ×1

templates ×1