Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/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
C++ 在基础之后选择专门的模板-为什么_C++_Templates - Fatal编程技术网

C++ 在基础之后选择专门的模板-为什么

C++ 在基础之后选择专门的模板-为什么,c++,templates,C++,Templates,我有以下代码: template<typename T> struct Container {}; template <int a, int b, typename T = Container<bool>> struct temp; template <int a, int b, typename T> struct temp<a, b, Container<T>> { using type = void; };

我有以下代码:

template<typename T> struct Container {};

template <int a, int b, typename T = Container<bool>>
struct temp;

template <int a, int b, typename T>
struct temp<a, b, Container<T>> {
    using type = void;
};

int main()
{

    static_assert(std::is_same<temp<0, 1>::type, void>::value, "error");

}
模板结构容器{};
模板
结构温度;
模板
结构温度{
使用类型=无效;
};
int main()
{
静态断言(std::is_same::value,“error”);
}
我的问题是:为什么要实例化更专业的模板??


我预料会出现类似“找不到temp的定义”(对于基本模板)的错误,但是会选择更专业的定义。。有点像“第二轮模板查找”。为什么会发生这种情况?

选择的更专业的一个是模板专门化的点。否则就没用了。是的,但我很困惑,在模板结构的所有主体之前都在考虑参数列表。专门化的一个主要用例是提供一些在主模板不起作用时可以起作用的东西。@t.C.谢谢,此时的问题是:为什么要将附加到参数列表的默认参数传递给基础模板?