Reading C++ Templates: The Complete Guide and it says
Note that templates cannot be declared
in a function
It does not give explanation and/or cross reference to any other chapter in the book or external resource.
Could someone help in explaining this. Probably it is explained later in the book but not there yet. If explained earlier, I must have missed it.
Example:
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;
}
I do not understand the error message from gcc either. The error message says:
expected primary-expression before "template"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…