0
考虑下面的现有代码(编译和执行如预期):如何在C++中声明一个带有前向声明模板类的模板类对象的extern数组?
/* File foo.h */
extern const struct Foo bar[]; /* Definition in foo.cpp */
struct Foo
{
Foo(int i) : Foo(bar[i]) {}
int x;
};
我现在想换Foo
到模板类,使得:
template <typename T>
struct Foo
{
Foo(int i) : Foo(bar[i]) {}
T x;
};
我现在需要声明extern const struct Foo bar[]
以便代码编译?