The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
We recommend using Visual Studio 2017

Compiler Error C2248


The latest version of this topic can be found at Compiler Error C2248.

member' : cannot access 'access' member declared in class 'class'

Members of a derived class cannot access private members of a base class. You cannot access private or protected members of class instances.

See Knowledge Base article KB243351 for more information on C2248.

The following sample generates C2248:

// C2248.cpp  
#include <stdio.h>  
class X {  
   int  m_pubMemb;  
   void setPrivMemb( int i ) {  
      m_privMemb = i;  
      printf_s("\n%d", m_privMemb);  
   int  m_protMemb;  
   int  m_privMemb;  
} x;  
int main() {  
   x.m_pubMemb = 4;  
   printf_s("\n%d", x.m_pubMemb);  
   x.m_protMemb = 2;   // C2248 m_protMemb is protected  
   x.m_privMemb = 3;   // C2248  m_privMemb is private  
   x.setPrivMemb(0);   // OK uses public access function  

Another conformance issue that exposes C2248 is the use of template friends and specialization. For more information, see Linker Tools Error LNK2019.

// C2248_b.cpp  
template<class T>  
void f(T t) {  
   t.i;   // C2248  
struct S {  
   int i;  
   S() {}  
   // Delete the following line to resolve.  
   friend void f(S);   // refer to the non-template function void f(S)  
   // Uncomment the following line to resolve.  
   // friend void f<S>(S);  
int main() {  
   S s;  

Another conformance issue that exposes C2248 is when you attempt to declare a friend of a class and when the class is not visible to the friend declaration in the scope of the class. In this case, grant friendship to the enclosing class to resolve the error.

// C2248_c.cpp  
// compile with: /c  
class T {  
   class S {  
      class E {};  
   friend class S::E;   // C2248  
class A {  
   class S {  
      class E {};  
      friend class A;   // grant friendship to enclosing class  
   friend class S::E;   // OK