Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Compiler Error C2691

'data type' : a managed array cannot have this element type

The type of a managed array element can be a value type or a reference type.

The following sample generates C2691:

// C2691a.cpp
// compile with: /clr
class A {};

int main() {
   array<A>^ a1 = gcnew array<A>(20);   // C2691
   array<int>^ a2 = gcnew array<int>(20);   // value type OK
}

The following sample generates C2691:

// C2691b.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
int main() {
   int * a1 __gc[];   // C2691
   int * a1 = new int [20];   // OK
}

C2691 can also occur if you attempt to define a jagged array using Managed Extensions for C++. Jagged arrays are supported in the current syntax, see Arrays (C++ Component Extensions) for more information.

The following sample generates C2691:

// C2691c.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
using namespace System;
int main() {
   Int32 myJaggedArray[][] = new Int32 [50][];   // C2691
}
Show:
© 2015 Microsoft