Article ID: 240866 - Last Review: July 5, 2005 - Revision: 1.1

BUG: ERROR C2989 and C2988 on Class Template Partial Specializations

This article was previously published under Q240866

On This Page

Expand all | Collapse all

SYMPTOMS

You may get the following error message if you try to use class template partial specializations:
error C2989: 'A<T,2>' : template class has already been defined as a non-template class error C2988: unrecognizable template declaration/definition
Please refer to the sample in the More Information section for details.

CAUSE

The compiler does not support class template partial specializations as specified in the C++ Standard (14.5.4.1) quoted here:
1- A primary class template declaration is one in which the class template name is an identifier. A template declaration in which the class template name is a template-id, is a partial specialization of the class template named in the template-id. A partial specialization of a class template provides an alternative definition of the template that is used instead of the primary definition when the arguments in a specialization match those given in the partial specialization (temp.class.spec.match). The primary template shall be declared before any specializations of that template. If a template is partially specialized then that partial specialization shall be declared before the first use of that partial specialization that would cause an implicit instantiation to take place, in every translation unit in which such a use occurs; no diagnostic is required.
Please refer to the C++ Standard section 14.5.4 for more information on this.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

The following code sample demonstrates the error.
//test.cpp
// compiler option needed: none

//  primary template
template<class T, int I> struct A {
	void f();
};

template<class T, int I> void A<T,I>::f() { }

//  class template partial specialization
template<class T> struct A<T,2> {
	void f();
	void g();
	void h();
};

				

APPLIES TO
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
Keywords: 
kbbug kbtemplate kbcpponly kbcompiler KB240866
 

Article Translations