【发布时间】:2016-10-12 12:33:28
【问题描述】:
考虑一个代码:
#include <iostream>
template <class T>
struct outer {
template <class... Args>
struct inner {
static constexpr bool value = false;
};
template <class... Other>
struct inner<T, Other...> {
static constexpr bool value = true;
};
};
int main() {
std::cout << outer<int>::inner<int, void>::value << std::endl;
};
它确实可以在 g++ 和 clang++ 中编译,但我不相信它是合法的。据我所知,如果没有明确地专门化类本身,就不能例如专门化模板类的模板方法。为什么内部类的规则不同?
【问题讨论】:
-
您没有专门研究模板方法。您正在部分专攻一门完整的课程。
标签: c++ templates c++11 variadic-templates template-specialization