"expected nested-name-specifier before ‘const’ error" with typename const in g++
Except when introducing a template type parameter, the keyword typename
must always be immediately followed by an optional global-scope ::
token and then a nested-name-specifier; that is, something which has one or more namespaces or classes, each followed by the ::
token.
See the syntax rules in the C++ Standard: 5.2 (function-style cast), 7.1.5.3 (elaborated type specifier), and 7.3.3 (using declaration).
Also, 14.6p5: "The keyword typename
shall be applied only to qualified names, but those names need not be dependent."
Microsoft's compiler is wrong to accept the invalid syntax.
Well, what's that typename
doing there? You are not referring to a nested type, so typename
is totally unnecessary there. I'd say that the error is caused by that unjustified use of typename
, not by ordering of the parts of the declaration or anything else.
It should be just
const DD<T>& mContainer;
or even
const DD& mContainer;