FIX: ClassView Cannot Add Member Functions To Template Classes (192629)



The information in this article applies to:

  • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 5.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q192629

SYMPTOMS

The following error occurs when trying to add member functions to template classes using ClassView:
Unable to create the implementation of this function

RESOLUTION

To add member functions to a template class, you must manually enter the functions into the source files.

STATUS

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

This problem was corrected in Microsoft Visual C++ .NET.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a default MFC AppWizard (exe).
  2. Add a generic class to the project:

    1. Select the project in ClassView.
    2. Right-click the mouse and select New Class.
    3. Select Generic from the Class Type combo box.
    4. Give the class a name, such as CMyGenericClass, and click OK.
  3. Edit this generic class declaration, constructor definition, and destructor definition by adding the template keyword along with the type list, for example:
          //generic class declaration:
    
          template <class c> class CMyGenericClass {
          public:
             CMyGenericClass();
             virtual ~CMyGenericClass();
          };
    
          //constructor and destructor definitions:
    
          template <class c> CMyGenericClass<c>::CMyGenericClass()
          {
          }
    
          template <class c> CMyGenericClass<c>::~CMyGenericClass()
          {
          }
    						
  4. In ClassView, right-click CMyGenericClass and select "Add Member Function."
  5. Enter the function name and return type. Click OK. A dialog box is displayed indicating the following error:
    Unable to create the implementation of this function
In Visual C++ 6.0, you do not have the ability to jump to a template function declaration from ClassView unless the template function is defined inside the class declaration (inline).

For additional information, please see the following article in the Microsoft Knowledge Base:

154112 ClassView Cannot Find Template Member Function Definition


Modification Type:MajorLast Reviewed:12/1/2003
Keywords:kbBug kbClassView kbfix kbide kbNoUpdate KB192629