------- Comment #6 from redi at gcc dot gnu dot org  2010-06-16 12:31 -------
(In reply to comment #3)
> > but it is an explicit specialization of the *definition* of the variable
> 
> No it is a specialization of the declaration.

It is a declaration of a specialization :)

> There are only specialization of declarations; never definitions.

Not true.

This is a definition of an explicit specialization:

template<>
const int MyTraits<int>::kValue = 1;

Such a definition must only occur in a single translation unit, otherwise you
get duplicate symbols.  To use it from multiple translation units you must
declare it in all and define it in one.

Here is a complete example:

template<class T=int> class MyTraits {
 public:
  static const T kValue;
};

// define the default specialization
template<class T>
const T MyTraits<T>::kValue = 0;

// declare an explicit specialization
template<>
const int MyTraits<int>::kValue;

int main(){
  const void * a = &(MyTraits<int>::kValue);
}

// define the explicit specialization
template<>
const int MyTraits<int>::kValue = 1;


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44548

Reply via email to