Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 模板参数中未命名的类/类型名_C++_Templates_C++11_C++14_Typename - Fatal编程技术网

C++ 模板参数中未命名的类/类型名

C++ 模板参数中未命名的类/类型名,c++,templates,c++11,c++14,typename,C++,Templates,C++11,C++14,Typename,我查看了的文档,其中有一个模板声明: template<typename SomeType> struct inner_type { typedef typename SomeType::type type; }; template < class T, class = typename T::type, // SFINAE failure if T has no member type class U = typename inn

我查看了的文档,其中有一个模板声明:

template<typename SomeType>
struct inner_type { typedef typename SomeType::type type; };
template <
    class T,
    class = typename T::type,            // SFINAE failure if T has no member type
    class U = typename inner_type<T>::type // hard error if T has no member type
                                          // (guaranteed to not occur as of C++14)
> void foo(int) {}
如果
t
已签名,则不编译,如果
t
未签名,则编译

我错过了什么

foo(0)编译良好

因为您指定了第二个模板参数,所以默认模板参数(即
typename T::type
)将不会被使用,也不会触发编译错误

如果你只写
foo(0)要使用默认模板参数,编译将失败

你的第二个样品也是一样的

声明一个未命名的类有什么意义


因为模板参数将不用于模板实现。

看起来您应该只调用
foo
作为
foo(0)
,而不是重写模板参数,从而从重载替换中删除模板。
template<class T, typename = std::enable_if_t<std::is_unsigned<T>::value>>
void foo(T t) {}