Search code examples
.netvisual-c++compiler-errorsc++-cliienumerable

C++ IEnumerable<int>=class->method(); in WinForms


I want the C++ equivalent to the following C#.

List<int> k = myclass.method().ToList();

In my standard C++ WinForms application I have tried the following:

IEnumerable<int>^ m=    myclass->method();

I get the following error:

C2872 IEnumerable ambiguous symbol

Please help me understand and resolve my issue.


Solution

  • There are two IEnumerables -- one in System::Collections, and one in System::Collections::Generic.

    Somehow you have both in scope (probably with using directives), so you'll need to either remove said using directives or fully qualify the type name:

    System::Collections::Generic::IEnumerable<int>^ m = myclass->method();