Compiler Error C3281

Error Message

'operator' : global operator cannot have managed type 'type' in signature

A global operator cannot have a managed type in the function signature.

C3281 is only reachable using /clr:oldSyntax.

The following sample generates C3281:

// C3281.cpp
// compile with: /clr:oldSyntax
using namespace System;
__value struct S {
   int i;
   static S op_Addition(S s, char c) { s.i -= c; return s;}

S& operator+(S& s, int i) {   // C3281, do not use S in signature
   s.i += i;
   return s;

int main() {
   S s = {10};

   s = s + '\x5';   // calls S::op_Addition

   s = s + 10;   // calls global operator+

Community Additions