Microsoft KB Archive/138446

= FIX: Inlined Templated Member Functions Cannot Be Specialized =

Article ID: 138446

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 2.1
 * Microsoft Visual C++ 2.2
 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 4.1 Subscription
 * Microsoft Visual C++ 4.2 Enterprise Edition
 * Microsoft Visual C++ 4.2 Professional Edition

-



This article was previously published under Q138446



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.



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: kbbug kbfix KB138446

-

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

© Microsoft Corporation. All rights reserved.