Microsoft KB Archive/150573

= FIX: C2084 When Template Class Constructor Has No Body =

Article ID: 150573

Article Last Modified on 7/5/2005

-

APPLIES TO


 * 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 Q150573



SYMPTOMS
The following error occurs when a template class is explicitly instantiated and it has more than one constructor, at least one of which does not have a body defined and at least one of which is defined outside of the class:

error C2084: function ' ' already has a body



WORKAROUND
This is the preferred workaround. Give every constructor a body. The body is defined inside or outside the template class.

-or-

 Place all the existing constructor bodies inside the template class definition.

NOTE: You get the following warning associated with the explicit instantiation request:

warning C4661: : no suitable definition provided for explicit instantiation request

This warning is issued when a template class does not have all its members defined and an explicit instantiation request is made. This warning also causes the compiler to ignore the instantiation request. -or-

 Instantiate the template class implicitly rather than explicitly. In this case, the instantiation occurs when declaring an object using the template class, but the C2084 does not.

NOTE: the sample code in this article gives examples of explicit versus implicit template instantiation.



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
/* Compile options needed: /c */

template   class A { public: A;            // give this ctor a body for workaround 1 A(const T&); };

template  A::A(const T&) {}; // move this ctor body // inside the class // definition for // workaround 2

template A ;    // this is an explicit instantiation - // comment this line out and uncomment the // next line for workaround 3 // A x = 3;    // this is an implicit instantiation

Additional query words: kbVC400bug

Keywords: kbbug kbfix kbvc500fix kbcpponly kbcompiler KB150573

-

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

© Microsoft Corporation. All rights reserved.