FIX: Template Keyword Can't Be Used Inside Class DeclarationsLast reviewed: September 19, 1997Article ID: Q148704 |
The information in this article applies to:
SYMPTOMSAny 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 ';' RESOLUTIONThe 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.
STATUSMicrosoft 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 INFORMATIONExamples where you need to use the keyword template within a class definition include:
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 <class T> void f(T, A *a) { a->x; } class A { private: int x; template <class T> friend void f(T, A*); }; |
Additional query words: 10.0 10.00 10.1 10.10 10.20
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |