Compiler Error C2581


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

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

type' : static 'operator =' function is illegal

The assignment (=) operator is incorrectly declared as static. Assignment operators cannot be static. For more information, see User-Defined Operators (C++/CLI).

The following sample generates C2581.

// C2581.cpp  
// compile with: /clr /c  
ref struct Y {  
   static Y ^ operator = (Y^ me, int i);   // C2581  
   Y^ operator =(int i);   // OK