Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
the type 'type' (return type of GetEnumerator) must have a suitable public MoveNext member function and public Current property
Remarks
User-defined collection classes must contain definitions for MoveNext
and Current
.
For more information, see for each, in.
Example
The following sample generates C3287.
// C3287.cpp
// compile with: /clr
using namespace System;
ref struct R {
bool MoveNext() {
return true;
}
property Object^ Current {
Object^ get() {
Object ^ o = gcnew Object;
return o;
}
}
};
ref struct R2 {
R ^GetEnumerator() {
R^ r = gcnew R;
return r;
}
};
ref struct T {};
ref struct T2 {
T ^GetEnumerator() {
T^ t = gcnew T;
return t;
}
};
int main() {
for each (int i in gcnew T2) {} // C3287
for each (int i in gcnew R2) {} // OK
}