Microsoft KB Archive/148704

= FIX: Template Keyword Can't Be Used Inside Class Declarations =

Article ID: 148704

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft Visual C++ 4.0 Standard Edition
 * 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 Q148704



SYMPTOMS
Any attempt to use the keyword 'template' within a class definition results in the following two errors:

error C2059: syntax error : 'template'

error C2238: unexpected token(s) preceding ';'



RESOLUTION
The resolution will vary according to the circumstances. For example, when declaring a template function to be a friend of a non-template class, find another way to manipulate the members of the class; for example, declare them to be public instead of private or provide public access member functions.



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.



MORE INFORMATION
Examples where you need to use the keyword template within a class definition include:


 * Declaring a template function to be a friend of a non-template class.
 * Declaring a template class to be a friend of a non-template class.
 * Declaring a template function as a member of a non-template class.

Sample Code
/* Compile options needed: None This sample illustrates the case of declaring a template function to be a friend of a non-template class. */

class A;  template  void f(T, A *a)  { a->x; }

class A { private: int x;      template  friend void f(T, A*); };

Additional query words: kbVC400bug 10.0 10.00 10.1 10.10 10.20

Keywords: kbbug kbfix kblangcpp kbvc500fix kbcpponly kbcompiler KB148704

-

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

© Microsoft Corporation. All rights reserved.