編譯器錯誤 C2107
不合法的索引,不允許間接取值
下標會套用至未評估為指標的表達式。
範例
如果您不正確地使用 this
實值類型的指標來存取類型的預設索引器,可能會發生 C2107。 如需詳細資訊,請參閱指標的this
語意。
下列範例會產生 C2107。
// C2107.cpp
// compile with: /clr
using namespace System;
value struct B {
property String ^ default[String ^] {
String ^ get(String ^ data) {
return "abc";
}
}
void Test() {
Console::WriteLine("{0}", this["aa"]); // C2107
Console::WriteLine("{0}", this->default["aa"]); // OK
}
};
int main() {
B ^ myb = gcnew B();
myb->Test();
}