Microsoft KB Archive/140605

= PRB: C2059 When Declaring Friend Template Functions in a Class =

Article ID: 140605

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft Visual C++ 4.0 Professional Edition
 * Microsoft Visual C++ 5.0 Learning Edition

-



This article was previously published under Q140605



SYMPTOMS
Attempting to declare a friend template function in a class definition may result in the following errors:

error C2059: syntax error: 'template'

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



CAUSE
This is a relatively new language feature that is currently not supported by the Visual C++ 4.0 compiler. For example, the following code will generate the errors noted above.

Sample Code
/* Compile options needed: none class A; template  void f(T, A *a) { a->x; }

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

int main(void) {  A a;   f(5, &a); f(1.5, &a); return 0; }



STATUS
This behavior is by design.

Additional query words: 4.00

Keywords: kbprb kbcompiler KB140605

-

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

© Microsoft Corporation. All rights reserved.