函数模板的显式专门化,用于完全专门化的类模板
Explicit specialization of a function template for a fully specialized class template
我试图在类模板的专门化中专门化一个函数,但无法找到正确的语法:
template< typename T >
struct Foo {};
template<>
struct Foo< int >
{
template< typename T >
void fn();
};
template<> template<>
void Foo< int >::fn< char >() {} // error: too many template-parameter-lists
在这里,我试图将fn
专门化为char
,这是在专门化int
的Foo
内部。但是编译器不喜欢我写的东西。那么什么应该是正确的语法呢?
你不必说你专业化了两次。
您只在此处专门化一个功能模板
template<> void Foo<int>::fn<char>() {}
在Coliru上直播
template< typename T >
struct Foo {};
template<>
struct Foo< int >
{
template< typename T >
void fn();
};
template<> void Foo<int>::fn<char>() {}
int main() {
Foo<int> f;
f.fn<char>();
}
相关文章:
- 如何在编译时专门化大型模板函数中的小部分
- 错误 C2893 无法专门化函数模板'unknown-type std::invoke(_Callable &&,_Types &&...)'
- 从 std 命名空间中专门化函数模板的想法有多糟糕?
- 如何专门化模板构造函数模板
- 专门化采用通用引用参数的函数模板
- 使用decltype尾部返回类型专门化函数模板
- 为模板化派生类专门化函数模板
- 如何专门化容器的函数模板
- 为模板函数专门化一个模板类
- 显式函数模板专门化选择了错误的专门化
- 如何部分专门化可变模板函数
- C++模板-专门化函数
- 在单独的.cpp文件中专门化函数模板
- 如何专门化具有多个参数的函数模板
- 如何专门化此模板成员函数
- 函数模板的显式专门化,用于完全专门化的类模板
- 函数模板专门化
- 二进制搜索的一个函数模板专门化
- 创建专门化函数模板的最佳方法是什么?
- c++中专门化函数模板的语法