Compiler Error C3262
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Compiler Error C3262.
invalid array indexing: '#' dimension(s) specified for '#'-dimensional 'array type'
An array was improperly subscripted. The number of indices may not match the number of dimensions in the array.
The following sample generates C3262:
// C3262.cpp
// compile with: /clr
#using <mscorlib.dll>
using namespace System;
#define ARRAY_SIZE 2
ref class MyClass {
public:
int m_i;
};
// returns a multidimensional managed array of a reference type
array<MyClass^, 2>^ Test0() {
int i, j;
array< MyClass^, 2 >^ local = new array< MyClass^, 2 >
(ARRAY_SIZE, ARRAY_SIZE);
for (i = 0 ; i < ARRAY_SIZE ; i++)
for (j = 0 ; j < ARRAY_SIZE ; j++) {
local[i][j] = new MyClass; // C3262
// try the following line instead
// local[i,j] = new MyClass;
local[i,j] -> m_i = i;
}
return local;
}
int main() {
int i, j;
array< MyClass^, 2 >^ MyClass0;
MyClass0 = Test0();
}
Managed Extensions for C++
The following sample generates C3262:
// C3262b.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
int main() {
int iArr __gc[,] = new int __gc[10,20];
iArr[1,2,3]; // C3262: 3 dimensions specified for 2-dimensional array
}
Show: