【发布时间】:2019-11-17 20:01:08
【问题描述】:
如何创建嵌套模板结构实现? 例如,如果我有:
foo.h:
template<class T>
class foo
{
template<class U>
struct bar
{
U u;
bar(U u);
...
};
...
};
和
foo.cpp
include "foo.h"
...
template<class T, class U>
foo<T>::bar<U>::bar(U u) : u(u) { }
...
我收到不同的语法错误,例如“缺少';'”等。 我做错了什么?
【问题讨论】:
-
模板只是标题。所以没有警察档案。如果要在 cop 文件中实现,则需要在 header 中实例化它们。
标签: c++ templates struct nested