Microsoft KB Archive/190966

= BUG: IntelliSense Limitations with Templates =

PSS ID Number: 190966

Article Last Modified on 10/15/2002

-

The information in this article applies to:


 * Microsoft Visual C++, 32-bit Enterprise Edition 6.0
 * Microsoft Visual C++, 32-bit Professional Edition 6.0
 * Microsoft Visual C++, 32-bit Learning Edition 6.0
 * Microsoft Visual C++ .NET (2002)

-



This article was previously published under Q190966



SYMPTOMS
This article focuses on the limitations of IntelliSense when working with templates.
 * IntelliSense does not recognize template member functions defined outside of the template class.

When a template member function is defined outside of the template class, it does not appear in an instantiated template object's Member list, and does not provide Parameter and Type Info. It also does not appear in the ClassView pane. With Visual C++ 6.0, the only way to have IntelliSense work correctly with template member functions is to define all member functions inside of the template class declaration.
 * Coding inside of nonclass template functions does not fully utilize IntelliSense.

IntelliSense does not parse the bodies of template functions that are not member functions of a class. As a result, most IntelliSense features do not work inside of a template function definition.
 * Template class specializations are not properly interpreted by IntelliSense.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION
Consider the following code sample. Comments that are examples are marked with \\EXAMPLE. The code directly below needs to be uncommented in order to reproduce the problem. The comments following the code explain the problem:

Sample Code
//Test.cpp #include 

// A Template Class //   template    class TempClass {  public: TempClass(void){} ~TempClass(void){} int MemberSet(T a, int b); int GetSize {  return arraysize; }  private: T Tarray[i]; int arraysize; };

// A Simple Class //   class TestClass {  public: TestClass(void){} ~TestClass(void){} int m;     int n;   };

// Template Member Function Defined outside of the template class //   template    int TempClass::MemberSet(T a, int b)   { if( ( b >= 0 ) && (b < i) ) {       Tarray[b++] = a;        return sizeof( a ); }     else return -1; };

// Template Class //   template    class Print {  public: // Declare an instance of TestClass TestClass te;

// EXAMPLE //te. // #2 No members displayed // all types but char

void f(int, double) {        printf(&quot;Print\n&quot;); }  };

// Specialization of Print  // template <> class Print {  public: // just for chars void f(char*) {        printf(&quot;Print \n&quot;); }  };

void main {  TempClass t;

// EXAMPLE //t. // #1 MemberSet is absent from the member list // MemberSet does not appear in the ClassView pane // Define MemberSet in the TempClass declaration // to correct this problem

Print pc;

// EXAMPLE //pc.f(  // #3   // pc.f  Tool tip shows all types but char   // pc.f( Parameter list is int, double }

