如何声明模板类的模板?看下面的代码:如何声明模板类的模板
File: A.h
class A
{
...
...
};
File: B.h
template <typename U>
class B
{
...
...
};
File C.h
template <class T>
class C
{
...
...
};
File C.cpp
//In this file I am able to write template declaration for class A(non-template class)
#include "A.h"
template C<A>; //this works fine.
How can I write the same for class B(which is a template class.)
#include "B.h"
template C<What should I write here for class B?>;
请注意,C++ 03编译器*需要*将'>>'看作移位运算符,而C++ 0x(可能是C++ 11)编译器将/不需要这里的空间。 – 2011-05-06 13:02:02
@Christopher - 我用过的编译器并不是那么严格,而且似乎是从上下文中区分出来的。 – 2011-05-06 13:24:30
大多数编译器默认情况下并不真正遵循任何标准,即使使用“严格”标志,也很少这样做。尽管如此,这是C++ 03标准中一个非常着名的缺陷,所以我当然希望你的编译器至少在文档中清楚地说明他们在这方面违反了规范。 (并不是说在这种情况下我有一个很大的问题。) – 2011-05-06 13:55:20