Export (0) Print
Expand All
Expand Minimize

Compiler Error C2108

subscript is not of integral type

The array subscript is a noninteger expression.

C2107 can occur if you incorrectly use the this pointer of a value type to access the type's default indexer. For more information, see Semantics of the this Pointer in Value and Reference Types.

The following sample generates C2107.

// C2108.cpp
// compile with: /clr
using namespace System;

value struct B {
   property Double default[Double] {
      Double get(Double data) {
         return data*data;
      }
   }
   void Test() {
      Console::WriteLine("{0}", this[3.3]);   // C2108
      Console::WriteLine("{0}", this->default[3.3]);   // OK
   }
};

int main() {
   B ^ myb = gcnew B();
   myb->Test();
}

Community Additions

ADD
Show:
© 2014 Microsoft