tags:

views:

151

answers:

1

Here is my code:

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;

namespace Tests {
    ref class MyCollection : public IEnumerable<int> <----HERE!

The C# compiler, for instance, will recognize that the only IEnumerable<T> it has in those namespaces is from System::Collections::Generic. Why can't the C++/CLI compiler do the same? Unlesss I type its full name or at least Generic::IEnumerable<int>, it won't recognize it and will fire a C2872 error: ambiguous symbol.

Am I missing something here?

Thanks

+3  A: 

Given your namespaces IEnumerable is ambiguous

MS define IEnumerable in both System::Collections and System::Collections::Generic which of the 2 do you want your code to use?

Mark
Erm, one is generic and the other isn't? Shouldn't be hard to pick which one to use, and furthermore, c# compiler isn't confused by it.
devoured elysium
How does the compiler know *in advance* that it should pick the generic version? It hasn't yet parsed the `<int>`, and even when it does, it first needs to determine that the `<` is the beginning of a generic type, and not the `less than` operator. And it still has to parse C++ correctly, so they can't arbitrarily change how it parses code.
jalf
C# and C++ languages are different and so parse the code in different ways
Mark
So you mean c++ compiler doesn't read it as IEnumerable<int> but as IEnumerable (space) int?
devoured elysium
I think it reads it as IEnumerable only and finds the definition from that
Mark
Well it must read the int, otherwise he wouldn't know which kind of generic it is, would it?
devoured elysium
It is the rules of C++ it works in this defined way
Mark