Compiler Error C2255

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

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

element' : not allowed outside of a class definition

For example, a nonmember function is declared a friend.

The following sample generates C2255:

// C2255.cpp  
// compile with: /c  
class A {  
private:  
   void func1();  
   friend void func2();  
};  
  
friend void func1() {}   // C2255  
void func2(){}  

Show: