RSS
Follow Us
Contribute
 
 
 
 

Error C2108: subscript is not of integral type

 
We need YOUR SKILLS in this collaborative work, to build the largest solution center for error messages.

From $1

Table of contents
  1. 1. Cause
  2. 2. Solution
  3. 3. About This Article

Cause

This error can occur if you incorrectly use the this pointer of a value type to access the type's default indexer. Ex:

// 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
   }
};

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

Solution

Possible resolution:

   void Test() { 
      Console::WriteLine("{0}", this->default[3.3]);   // OK
   }

About This Article

This article is a derivative work based on Compiler Error C2108 which is provided by MSDN Community Content - Visual C++.

 
 
 
 
Comments