Compiler Error C2804
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Compiler Error C2804

Error Message

binary 'operator operator' has too many parameters

The overloaded binary operator is declared with more than one parameter. The first parameter of a binary operator, whose type is the operator's enclosing type, is implied.


The following sample generates C2804.

// C2804.cpp
// compile with: /c
class X {
   X operator+ ( X , X );   // C2804 two parameters
   X operator+ ( X );   // para1 type implicitly X&, para2 type 'X'

int main() {
   X x, y;
   x + y;   // equivalent to x.operator+(y)

The following sample generates C2804.

// C2804_2.cpp
// compile with: /clr /c
ref struct Y {
   Y^ operator +(Y^ hY, int i);   // C2804
   static Y^ operator +(Y^ hY, int i);   // OK
   Y^ operator +(int i);   // OK
© 2015 Microsoft