DOCUMENT:Q138446 30-JUL-2001 [visualc] TITLE :FIX: Inlined Templated Member Functions Cannot Be Specialized PRODUCT :Microsoft C Compiler PROD/VER:2.0 2.1 2.2 4.0 4.1 4.2 OPER/SYS: KEYWORDS: ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - The C/C++ Compiler (CL.EXE), included with: - Microsoft Visual C++, 32-bit Editions, versions 2.0, 2.1, 2.2, 4.0, 4.1 - Microsoft Visual C++, 32-bit Enterprise Edition, version 4.2 - Microsoft Visual C++, 32-bit Professional Edition, version 4.2 ------------------------------------------------------------------------------- SYMPTOMS ======== When specializing a member function that is defined inside the class template, the specialized member function never gets called although there is no compiler error or linker error reported. RESOLUTION ========== Do not define the member function in the class template. See the Sample Code below for an example. 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 to Reproduce Problem -------------------------------- /* Compile options needed: Default */ # include template struct TempStruct { void bar() { cout << "Template generated" << endl; } // Change the previous line into a comment and execute the following // line to work around the problem: // void bar(); }; // Execute the following lines to work around the problem: // template // inline void TempStruct::bar() // { // cout << "Template generated" << endl; // } void TempStruct::bar() { cout << "Template specialized" << endl; } void main() { TempStruct F1; TempStruct F2; F1.bar(); F2.bar(); } // The output from the program is: Template generated Template generated // The output should be: Template generated Template specialized Additional query words: 9.0 9.00 10.0 10.00 10.10 10.20 ====================================================================== Keywords : Technology : kbVCsearch kbAudDeveloper kbCVCComp Version : 2.0 2.1 2.2 4.0 4.1 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.