Microsoft KB Archive/128789

= BUG: LNK2001 on Member Function When Use Nested Class Template =

Article ID: 128789

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 2.1
 * 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
 * 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 Q128789



SYMPTOMS
When you build a program that uses nested class templates, the following link error is generated:

test.obj: error LNK2001: unresolved external symbol

"?Funtion@BB@?$AA@HH@@QAEHXZ

( public: int __thiscall AA::BB::Funtion(void) )"



CAUSE
The compiler does not generate code for the member function in the nested class template.



RESOLUTION
To work around the problem, use one of the following suggestions:
 * Define the function in the class declaration as an inline function. Be sure to define the function body in the class declaration. Defining the function as an inline function outside the class declaration will not eliminate the problem.

-or-
 * Use the member function specialization technique to work around the problem. This technique is demonstrated in the "Sample Code" section of this article.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.



MORE INFORMATION
The following code can be used to reproduce or work around the problem.

Sample Code
/* Compile options needed: None. */

#include 

template  class AA  { public: class BB      { public: int Function;

// Work around #1, replace the previous line with //       int Function { return 0; } };  };

// Work around #2, uncomment the following function // AA::BB::Function // {  //   return 0; // }

template  int AA::BB::Function {     return 0; }

void main {    AA::BB b;     printf( "%d\n", b.Function ); }

Additional query words: 9.0 9.00 9.1 9.10 10.00 10.10 10.20

Keywords: kbbug kbcpponly kbpending kbcompiler KB128789

-

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

© Microsoft Corporation. All rights reserved.