tags:

views:

120

answers:

2

In a template-declaration, explicit specialization, or explicit instantiation the init-declarator-list in the declaration shall contain at most one declarator. When such a declaration is used to declare a class template,no declarator is permitted.

Any one explain this ?

For me it is necessary that i need to check the compilers is following the ISO standard? It is our project please help me?

+3  A: 

That means you cannot write

template <class T> class A{} a, b;

or similarly

template <class T> A<T>::a=0, A<T>::b=1;

(imagine what would a, b be in the first case). For a more thorough explanation of declarators, see chapter 8 of the standard.

jpalecek
When such a declaration is used to declare a class template,no declarator is permitted ...it means?
BE Student
It means that in the first example, even single `a` would be wrong. Or put another way, a template class declaration cannot declare or define any variables, functions, or other types (eg. pointer to the class), while a non-templated declaration can.
jpalecek
+1  A: 

Back when C was king, it used to be common practice to write code like this:

struct { int x; int y; } pt1, pt2;

This code creates an anonymous struct and declares two variables of that type.

The standardese you quote basically says that you can't do that for template types. Thus, the following is ill-formed:

template <typename T> struct { T x; T y; } pt1, pt2;

The reason should be obvious--pt1 & pt2 don't have complete type--we don't know what T is when we declare them.

That style of declaration is quite uncommon in C++, however, so this is a somewhat inconsequential restriction.

Drew Hall