BUG: Template Friend Function Causes Compiler Error C2248Last reviewed: July 3, 1997Article ID: Q166109 |
The information in this article applies to:
SYMPTOMSThe compiler generates a compiler error C2248 as follows:
Error C2248: 'member' : cannot access member declared in class 'class'under the following circumstances: - If a class declares a template function as a friend function, and - If the template function definition appears after the class definition.
RESOLUTIONDo not declare a template function as a friend of a class.
STATUSMicrosoft 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 INFORMATIONThe following sample demonstrates the problem and the workaround.
Sample Code
/* Compile option: None */ class X; template <class T> void AFunction(X &x, T &t); class X { private: int m_n; public: template <class T> friend void AFunction(X &x, T &t) ; }; template <class T> void AFunction(X &x, T &t) { x.m_n = t; // C2248 here. } int main() { X x; int n; AFunction(x, n); return 0 ; }NOTE: Defining the template function before the class definition eliminates the compiler error C2248. But the compiler does not generate any code when you call the template function. |
Keywords : CPPIss CPPLngIss kbtool vcbuglist500 kbbuglist
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |