Compiler Error C3470
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Compiler Error C3470.
type' : a class cannot have both an indexer (default indexed property) and an operator[]
A type cannot define both a default indexer and an operator[].
The following sample generates C3470
// C3470.cpp
// compile with: /clr
using namespace System;
ref class R {
public:
property int default[int] {
int get(int i) {
return i+1;
}
}
int operator[](String^ s) { return Convert::ToInt32(s); } // C3470
};
int main() {
R ^ r = gcnew R;
// return r[9] + r["32"] - 42;
}
Show: