Microsoft KB Archive/131376

= FIX: C2974 Error When Calling Templated Base Class Functions =

Article ID: 131376

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 2.1

-



This article was previously published under Q131376



SYMPTOMS
Calling a member function of a templated base class through the 'this' pointer produces the following erroneous error:

error C2974: '' : invalid template actual argument '#1', type expected.



RESOLUTION
Call the function without using the 'this' pointer.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was fixed in Microsoft Visual C++, 32-bit Edition, version 4.0.



MORE INFORMATION
The Visual C++ compiler generates the following errors when the following sample program (TEST.CPP), is compiled with the /D"SHOW_TEMPLATE_ERROR" option: test.cpp(20) : error C2974: 'A' : invalid template actual argument '#1', type expected test.cpp(20) : error C2231: '.B::A ::Afunc' : left operand points to 'class', use '->' test.cpp(20) : fatal error C1903: unable to recover from previous error(s); stop ping compilation

Sample Code to Demonstrate Problem
/* Compile options needed: none // #define SHOW_TEMPLATE_ERROR

template  class A { public: Type a;   void Afunc(void){}; };

template  class B: public A { public: void Bfunc {       this->A::Afunc; A::Afunc; } };
 * 1) ifdef SHOW_TEMPLATE_ERROR
 * 1) else
 * 1) endif

void main {   B b; }

Additional query words: 2.00 2.10

Keywords: kbbug kbfix kbcpponly kbcompiler KB131376

-

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

© Microsoft Corporation. All rights reserved.