We recommend using Visual Studio 2017

Compiler Error C2831

 

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

operator operator' cannot have default parameters

Only three operators can have default parameters:

  • new

  • Assignment =

  • Left parenthesis (

The following sample generates C2831:

// C2831.cpp  
// compile with: /c  
#define BINOP <=  
class A {  
public:  
   int i;  
   int operator BINOP(int x = 1) {   // C2831  
   // try the following line instead  
   // int operator BINOP(int x) {  
      return i+x;  
   }  
};  

Show: