dra*_*oot 5 c++ templates template-specialization
我正在尝试在类模板的特化中专门化一个函数,但无法找到正确的语法:
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
Run Code Online (Sandbox Code Playgroud)
在这里,我想专门fn为char,这是内部Foo专门为int.但是编译器不喜欢我写的东西.什么应该是正确的语法呢?
你不必说你专攻两次.
你只是在这里专门化一个功能模板
template<> void Foo<int>::fn<char>() {}
Run Code Online (Sandbox Code Playgroud)
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>();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
76 次 |
| 最近记录: |