I have this code in C++
template<typename T>
class DD
: public enumerables<T>
{
...
private:
typename const DD<T>& mContainer;
}
And it gives me two error messages :
What's wrong with typename const
code? It compiles fine with MSVC C++.
typename DD<T>& const mContainer;
and const typename DD<T>& mContainer;
give me the same error.
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With