DOCUMENT:Q163995 30-JUL-2001 [visualc] TITLE :FIX: C2989 Declaring Template Class in a Namespace PRODUCT :Microsoft C Compiler PROD/VER:4.2 OPER/SYS: KEYWORDS:kbCompiler kbCPPonly kbLangCPP kbVC kbVC500fix kbHWx86 ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - The C/C++ Compiler (CL.EXE), included with: - Microsoft Visual C++, 32-bit Enterprise Edition, version 4.2 - Microsoft Visual C++, 32-bit Professional Edition, version 4.2 ------------------------------------------------------------------------------- SYMPTOMS ======== A template class is defined inside a namespace that has the same name as a non-template class declared at global scope. When you compile this construct, the following error message appears: error C2989: '' : template class has already been defined as a non-template class RESOLUTION ========== There are 3 ways to work around this problem. 1. Change the name of one of the classes involved. If this is possible, it may be the best solution because having two different classes with the same name could lead to confusion. 2. Move the definition of the non-template class so that it appears after the definition of the template class. See sample code below. 3. Move the definition of the non-template class into a namespace (other than the one the template class is defined in). STATUS ====== Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 5.0. MORE INFORMATION ================ Sample Code ----------- /* Compile options needed: none */ class test {}; // Move this line below namespace tester for resolution #2. namespace tester { template class test {}; } Additional query words: C2989 template namespace ====================================================================== Keywords : kbCompiler kbCPPonly kbLangCPP kbVC kbVC500fix kbHWx86 Technology : kbVCsearch kbAudDeveloper kbCVCComp Version : 4.2 Issue type : kbbug Solution Type : kbfix ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2001.