Compiler Warning (level 4) C4460
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 Warning (level 4) C4460

Error Message

CLR operator 'operator', has parameter passed by reference. CLR operator 'operator' has different semantics from C++ operator 'operator', did you intend to pass by value?

You passed a value by reference to a user-defined CLR operator. If the value is changed inside the function, note that the value returned after the function call will be assigned the return value of the function. In standard C++, the changed value is reflected after the function call.


The following sample generates C4460.

// C4460.cpp
// compile with: /W4 /clr 
#include <stdio.h>

public value struct V {
   static V operator ++(V& me) {   // C4460
   // try the following line instead
   // static V operator ++(V me) {

      printf_s(__FUNCSIG__ " called\n");
      V tmp = me;
      return tmp;
   int m_i;

int main() {
   V v;
   v.m_i = 0;

   printf_s("%d\n", v.m_i);   // Should print 0
   v++;   // Translates to "v = V::operator ++(v)"
   printf_s("%d\n", v.m_i);   // will print 0, hence the warning
© 2015 Microsoft