Export (0) Print
Expand All
Expand Minimize

Compiler Error C2690

Error Message

'operator' : cannot perform pointer arithmetic on a managed array

Pointer arithmetic is not allowed on a managed array. Use array index notation to traverse the array.

The following sample generates C2690:

// C2690.cpp
// compile with: /clr
int main() {
   array<int> ^p = gcnew array<int>(5);
   for (int i = 0 ; i < 5 ; i++)
      p[i] = i;
   for (i = 0 ; i < 5 ; i++) {
      System::Console::WriteLine(p++);   // C2690
      System::Console::WriteLine(p[i]);   // OK
   }
}

Managed Extensions for C++

Pointer arithmetic is not allowed on a __gc array. Use array index notation to traverse the array.

The following sample generates C2690:

// C2690b.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
using namespace System;

int main() {
   String* x[] = new String*[10];
   x[0] = "test";
   Console::WriteLine(x[0]);
   x++;   // C2690
}

Community Additions

ADD
Show:
© 2014 Microsoft