BUG: C2248: No Access for Friend Class in a Template ClassLast reviewed: May 21, 1997Article ID: Q168384 |
The information in this article applies to:
SYMPTOMSDeclaring a template parameter type as a friend class of a template class, causes the compiler error C2248:
error C2248: 'xx' : cannot access private member declared in class 'XX<class T>'Member access is not granted to friend class T, where T is a template parameter of the template class XX.
CAUSEThe compiler treats typename T as a regular C++ class and not a template parameter type. This implies the following:
RESOLUTIONDo not declare a template parameter type as a friend of a template class. Specify the friend class using the regular C++ class name.
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 code demonstrates the problem.
Sample Code
/* * Compiler Options: none */ template <typename T> class Test { //template parameter T declared as friend class friend class T ; int m_i ; } ; class B { public: //Cannot access private member of template class Test //since class B is not recognized as friend class of //template class Test B() { tB.m_i = 0 ;} //C2248 here Test<B> tB ; } ; int main() { B bObj ; return 0 ; } |
Keywords : CPPIss CPPLngIss kberrmsg kbtool vcbuglist500 kbbuglist
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |