Basically, I mean the C ++ 03 standard, but, having a quick look at it, it should also be applicable to the C ++ 11 standard.
The following code was compiled and successfully executed in VC ++ 2010:
template<typename T> class CC { public: T f(T a) { return a*a; } }; template<> class ::CC<int> {
Note the syntax ::CC<int> for referencing a template defined in the global namespace. This is not the same as the NamespaceA::CC<int> syntax preceded by the :: operator. With some other tools, I tried to parse this using a grammar strictly from C ++ 03, but it gave me errors, and it seems to me that the standard takes only the form NamespaceA::CC<int> in the declaration of the head of the class.
On closer inspection, the problem is that the class-head is defined by this grammar in the standard:
class-head: class-key identifier(optional) base-clause(optional) class-key nested-name-specifier identifier base-clause(optional) class-key nested-name-specifier(optional) template-id base-clause(optional)
And since nested-name-specifier has the form AA::bb:: ..., it does not accept my ::CC . My question is why the C ++ standard does not allow the :: CC form? Is this just my misinterpretation of standard grammar? If the correct grammar looks like this:
class-head: ... class-key '::'(optional) nested-name-specifier(optional) template-id base-clause(optional)
Note that the above form is really used by the standard somewhere else, say when specifying the declarator identifier:
declarator-id: id-expression ::(optional) nested-name-specifier(optional) class-name
c ++ language-lawyer c ++ 11 c ++ 03 grammar
Javaman
source share