我已经学会了可以通过以下方式使用模板来创建数据结构:如何区分C++中的数据结构模板和函数模板?
template<typename T>
struct X {
T weight;
int age;
};
功能还可以使用以下方法模板:
template <class T>
T func_name(int age, T human) {
something_here;
}
之一的差 - 是不是在第一种情况下,我们使用typename
,而在第二种情况下,我们使用class
。
我发现,包含下面的代码:
template<typename S, typename T>
bool is_null(const row<T>& r)
所以,我无法理解的是,为什么我们结合使用typename
(而不是class
)与功能。我们不应该使用class
?
您可能会发现与您相关的[此问题](http://stackoverflow.com/questions/213121/use-class-or-typename-for-template-parameters)。或者也许[这个问题](http://stackoverflow.com/questions/2023977/c-difference-of-keywords-typename-and-class-in-templates) – WhozCraig 2013-03-11 16:03:36