编译器错误 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();
}