[英]Partial specialization with class template
我正在阅读此处给出的答案: https : //stackoverflow.com/a/23550519/1938163
我想知道为什么最后一行是模板结构的部分专业化
template<typename T> MyClass { public: };
template <typename T> struct Foo {void foo() {}};
template<> struct Foo<int> {void foo() { std::cout << "fooint";} };
// Why is this a partial specialization?
template<typename T> struct Foo< MyClass<T> > {void foo() {std::cout << "foo myclass";} };
我认为部分专长在于完全替换参数参数,如下所示
template <typename T, typename G> struct FooBar {};
template <typename G> struct FooBar<int, G>{}; // Partial specialization
完全专业化是指模板参数全部由具体类型替换并且模板参数列表为空。 MyClass<T>
不是具体的; 和
template<typename T> struct Foo<MyClass<T>> { ... };
它仍然由T
参数化,并且模板参数列表仍然包含T
例如,
template<> struct Foo<MyClass<int>> { ... };
将是Foo
的完全专业化,它比Foo<MyClass<T>>
更专业。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.