Microsoft KB Archive/240866

= BUG: ERROR C2989 and C2988 on Class Template Partial Specializations =

Article ID: 240866

Article Last Modified on 7/5/2005

-

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++ 6.0 Standard Edition

-



This article was previously published under Q240866



SYMPTOMS
You may get the following error message if you try to use class template partial specializations:

error C2989: 'A' : 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.



Steps to Reproduce Behavior
The following code sample demonstrates the error.

//test.cpp // compiler option needed: none

// primary template template struct A { void f; };

template void A::f { }

// class template partial specialization template struct A { void f; void g; void h; };

Keywords: kbbug kbtemplate kbcpponly kbcompiler KB240866

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.