We recommend using Visual Studio 2017

Compiler Error C3071


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

operator 'operator' can only be applied to an instance of a ref class or a value-type

A CLR operator cannot be used on a native type. The operator can be used on a ref class or a ref struct (a value type) but not a native type such as int or an alias for a native type such as System::Int32. These types can't be boxed from C++ code in a way that refers to the native variable, so the operator cannot be used.

For more information, see Tracking Reference Operator.

The following sample generates C3071.

// C3071.cpp  
// compile with: /clr  
class N {};  
ref struct R {};  
int main() {  
   N n;  
   %n;   // C3071  
   R r;  
   R ^ r2 = %r;   // OK