How to implement IEnumerable <int> from this C # code?
I am trying to convert this C # code to C ++ / cli code:
class MyRange : IEnumerable<int> { public IEnumerator<int> GetEnumerator() { return null; } IEnumerator IEnumerable.GetEnumerator() { return null; } } Here is my attempt:
namespace Tests { public ref class MyRange : System::Collections::Generic::IEnumerable<int> { private: virtual System::Collections::IEnumerator^ GetEnumerator() = System::Collections::IEnumerable::GetEnumerator { return nullptr; } virtual System::Collections::Generic::IEnumerable<int>^ GetEnumerator() { return nullptr; } }; } This gives me so many errors (like 20), that I donβt even think itβs worth putting them here.
I have been looking for all this and it looks like many people have the same problem as me.
+4
2 answers
Well, after a lot of fighting, I found some working code:
namespace Tests { ref class MyCollection : public Generic::IEnumerable<int> { public: virtual System::Collections::IEnumerator^ GetEnumeratorNonGeneric() = System::Collections::IEnumerable::GetEnumerator { return GetEnumerator(); } virtual Generic::IEnumerator<int>^ MyCollection::GetEnumerator() { return nullptr; } }; } +4