Microsoft KB Archive/829604

= &quot;C1001 Internal Compiler Error&quot; Error Message When You Compile a Template Method That Does Not Have a Return Type =

Article ID: 829604

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Common Language Runtime (included with the .NET Framework 1.1)

-



SYMPTOMS
In Microsoft Visual C++ .NET 2003, if you implement a template method without specifying the return type, you receive the following error message from the Microsoft C/C++ Compiler (Cl.exe) when you try to compile your code:

fatal error C1001: INTERNAL COMPILER ERROR

(compiler file 'msc1.cpp', line 2701)

Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information



RESOLUTION
To resolve this problem, specify the return type when you implement your template method. To do this, use code that is similar to the following modified code.

Note The following code is based on the sample that appears in the &quot;More Information&quot; section of this article. Therefore, this code may be different from your code. template  class tExample {   public: void fun1(void); void fun2(void); };

template  // To resolve C1001: INTERNAL COMPILER ERROR, // add void as the return type to match the function prototype. void tExample::fun1(void) { }

template  // To resolve C1001: INTERNAL COMPILER ERROR, // add void as the return type to match the function prototype. void tExample::fun2(void) { }



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section of this article.



Steps to Reproduce the Behavior
Note The compiler error message that you receive in Visual C++ .NET 2002 is different from the compiler error message that you receive in Visual C++ .NET 2003.

To reproduce this problem in Visual Studio .NET 2003, follow these steps:  Open a Visual Studio .NET 2003 Command Prompt window. To do this, click Start, point to Programs, point to Microsoft Visual Studio .NET 2003, point to Visual Studio .NET Tools, and then click Visual Studio .NET 2003 Command Prompt. Run the following command at the Visual Studio .NET 2003 command prompt to open a file named templateExample.cpp in a text editor such as Notepad:

notepad templateExample.cpp

  Paste the following code in the templateExample.cpp file: template  class tExample {   public: void fun1(void); void fun2(void); };

template <class T, class S> tExample<T, S>::fun1(void) { }

template <class T, class S> tExample<T, S>::fun2(void) { } </li> At the Visual Studio .NET 2003 command prompt, run the following command to try to compile the templateExample.cpp file:

cl /c templateExample.cpp

You receive the error message that appears in &quot;Symptoms&quot; section of this article.</li></ol>

If you try to compile the same code at a Visual Studio .NET 2002 command prompt, you receive the following compiler error messages:

error C2244: 'tExample<T,S>::fun1' : unable to match function definition to an existing declaration

a.cpp(5) : see declaration of 'tExample<T,S>::fun1' definition

'int tExample<T,S>::fun1(void)' existing declarations 'void tExample<T,S>::fun1(void)'

error C2954: template definitions cannot nest

a.cpp(15) : error C2244: 'tExample<T,S>::fun2' : unable to match function definition to an existing declaration

a.cpp(6) : see declaration of 'tExample<T,S>::fun2' definition 'int tExample<T,S>::fun2(void)' existing declarations 'void tExample<T,S>::fun2(void)'

Keywords: kberrmsg kbbug kbfix kbprogramming kbcode kbcompiler KB829604

-

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

© Microsoft Corporation. All rights reserved.