編譯器錯誤 C3915
'type' 沒有預設的索引屬性 (類別索引器)
類型沒有預設的索引屬性。
如需詳細資訊,請參閱 property。
範例
下列範例會產生 C3915。
// C3915.cpp
// compile with: /clr
ref class X {
public:
// uncomment property to resolve this C3915
// property int default[]
// {
// int get(int i)
// {
// return 863;
// }
// }
};
int main() {
X^ x = new X;
System::Console::WriteLine(x[1]); // C3915
}
如果您嘗試在相同的編譯中取用預設索引器,以及使用 定義 DefaultMemberAttribute的預設索引器,也可以發生 C3915。
下列範例會產生 C3915。
// C3915_b.cpp
// compile with: /clr
using namespace System;
[Reflection::DefaultMember("XXX")]
ref struct A {
property Double XXX[Double] {
Double get(Double data) {
return data*data;
}
}
};
ref struct B {
property Double default[Double] {
Double get(Double data) {
return data*data;
}
}
};
int main() {
A ^ mya = gcnew A();
Console::WriteLine("{0}", mya[3]); // C3915
B ^ myb = gcnew B();
Console::WriteLine("{0}", myb[3]); // OK
}