DOCUMENT:Q154112 11-FEB-2002 [visualc] TITLE :FIX: ClassView Cannot Find Template Member Function Definition PRODUCT :Microsoft C Compiler PROD/VER::4.0,4.1,4.2,6.0 OPER/SYS: KEYWORDS:kberrmsg kbui kbCompiler kbCPPonly kbVC kbVC400bug kbVC410bug kbVC420bug kbVC500fix kbV ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual C++, versions 4.0, 4.1 - Microsoft Visual C++, 32-bit Enterprise Edition, versions 4.2, 6.0 - Microsoft Visual C++, 32-bit Professional Edition, versions 4.2, 6.0 - Microsoft Visual C++, 32-bit Learning Edition, version 6.0 ------------------------------------------------------------------------------- SYMPTOMS ======== ClassView pops up the message "Cannot find the definition for this function" for some member functions of a template class. This happens for those member functions that return a template class, or a reference or pointer to a template class. The function must also be defined outside of the class. The sample code in the More Information section below demonstrates this problem. In Visual C++, version 6.0, ClassView cannot find any template member function or variable defined outside of the class. The error message reads: Cannot find the definition (implementation) of this function. RESOLUTION ========== The only workaround is to define the function inline by moving its body inside the class declaration. Note that defining the function outside the class declaration with the inline keyword will not solve the problem. Also note that projects with this problem will still build and run correctly; only the convenience of finding a function's definition via the ClassView is lost. 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. This bug reappeared in Microsoft Visual C++, version 6.0. This problem was corrected in Microsoft Visual C++ .NET. MORE INFORMATION ================ The following sample code will reproduce the problem. To reproduce, right click on "mult_by_scalar" while in the class view and select Go To Definition. For additional information, please see the following article in the Microsoft Knowledge Base: Q179012 ClassView Lacks "Go to Declaration" for Static Data Members Sample Code ----------- /* Compile options needed:none */ template class SimpleArray { public: SimpleArray(); ~SimpleArray(); SimpleArray& mult_by_scalar(T);// Cannot find the definition int Numelem(); private: int num_elts; T* ptr_to_data; }; template SimpleArray::SimpleArray() { num_elts=0; ptr_to_data = 0; } template SimpleArray::~SimpleArray() { delete [] ptr_to_data; } template SimpleArray& SimpleArray::mult_by_scalar(T rm) { return *this; } template int SimpleArray::Numelem(){ return num_elts; } Additional query words: ====================================================================== Keywords : kberrmsg kbui kbCompiler kbCPPonly kbVC kbVC400bug kbVC410bug kbVC420bug kbVC500fix kbVC600bug kbGrpDSTools kbNoUpdate Technology : kbVCsearch kbVC400 kbAudDeveloper kbVC410 kbVC420 kbVC600 kbVC32bitSearch Version : :4.0,4.1,4.2,6.0 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 2002.