阅读C++模板:完整指南,它说
请注意,模板不能在函数中声明
它不对书中的任何其他章节或外部资源给出解释和/或交叉引用.
有人可以帮忙解释一下.可能它会在本书后面解释,但还没有.如果先前解释过,我一定错过了它.
例:
int main()
{
class DummyClass // This compiles ok
{
int object;
};
template <typename T> // compile error "expected primary-expression before "template""
class DummyTemplate
{
T object;
};
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我也不明白gcc的错误信息.错误消息说:
expected primary-expression before "template"
Run Code Online (Sandbox Code Playgroud)