1

The chapter of Templates in the C++03 Standard starts with the following:

A template defines a family of classes or functions.

template-declaration:  
     exportopt template < template-parameter-list > declaration
template-parameter-list:
     template-parameter
     template-parameter-list , template-parameter

The declaration in a template-declaration shall

— declare or define a function or a class, or

— define a member function, a member class or a static data member of a class template or of a class nested within a class template, or

— define a member template of a class or class template.

A template-declaration is a declaration. A template-declaration is also a definition if its declaration defines a function, a class, or a static data member.

So from what I understand reading the bold text is that we can define static data-member-template , in addition to class -template and function-template. But I've never seen static data-member-template. How exactly is it defined? I tried the following, but GCC is not accepting it (ideone):

template<typename T> struct X{};

template<typename T>
struct A
{
   template<typename U> static X<U> data_member;
};

So I started doubting myself if I understood the quotation correctly. What exactly am I missing? Or how exactly can we define static data member template? What does the bold text mean?

Nawaz
  • 353,942
  • 115
  • 666
  • 851

2 Answers2

5

No, it refers to:

template<typename T> int A<T>::staticDataMember;
//                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~ declaration

If A is a class template like the following

template<typename T>
struct A { static int staticDataMember; };
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
0

You never gave the data_member an actual type.

template<typename T> struct X{};

template<typename T>
struct A
{
   static X<T> data_member;
};
Puppy
  • 144,682
  • 38
  • 256
  • 465
  • But that declaration is not of the form of `template < template-parameter-list > declaration` as the quotation says. – Nawaz May 28 '11 at 13:24