“attribute”:特性只允许出现在类索引器上(默认索引属性)
错误地使用了设计为应用于类索引器属性的特性。
有关详细信息,请参阅如何:在 C++/CLI 中使用属性。
示例
下面的示例生成 C3459。
// C3459.cpp
// compile with: /clr /c
public ref class MyString {
public:
[System::Runtime::CompilerServices::IndexerName("Chars")] // C3459
property int Prop;
};
// OK
public ref class MyString2 {
array<int>^ MyArr;
public:
MyString2() {
MyArr = gcnew array<int>(5);
}
[System::Runtime::CompilerServices::IndexerName("Chars")] // OK
property int default[int] {
int get(int index) {
return MyArr[index];
}
void set(int index, int value) {
MyArr[index] = value;
}
}
};