我的代码归结为:
//Just a templated array class .. implementation doesn't matter
template<int N>
struct Array {};
//A simple Traits like class
template<typename T>
struct MyTraits {}
//Specialization of the traits class
template<int N>
struct Foo< Array<N> >
{
static void monkey() {};
}
int main()
{
Foo< Array<3> >::monkey();
}
Run Code Online (Sandbox Code Playgroud)
不幸的是编译器不喜欢它......
test.cpp: In function ‘int main()’:
test.cpp|17| error: ‘monkey’ is not a member of ‘Foo<Array<3> >’
Run Code Online (Sandbox Code Playgroud)
我做错了什么,我该如何解决?谢谢
以下适用于我:
//Just a templated array class .. implementation doesn't matter
template<int N>
struct Array {};
//A simple Traits like class
template<typename T>
struct MyTraits {};
//Specialization of the traits class
template<int N>
struct MyTraits< Array<N> >
{
static void monkey() {};
};
int main()
{
MyTraits< Array<3> >::monkey();
}
Run Code Online (Sandbox Code Playgroud)
你的方式Foo是不正确的,因为你可以看到我改变它以匹配评论.此外,在声明Foo/ 之后,您丢失了分号MyTraits.最后,对于数组类,我建议你使用它size_t作为类型N.
| 归档时间: |
|
| 查看次数: |
173 次 |
| 最近记录: |