我最近安装了VS2012。在VS2010下可以正常编译的C++项目(带有.Net 4.0)无法识别VS2012上的HashSet<T>
。我什至尝试通过以下声明来明确表达:
System::Collections::Generic::HashSet< String^ >^ _reasons;
但这只会导致错误:
error C2039: 'HashSet' : is not a member of 'System::Collections::Generic
该文档说它在System.Collections.Generic中。 C++编译器不这么认为。
有什么想法吗?
最佳答案
HashSet <>是.NET的后期添加,它在.NET 3.5中可用。命名空间较旧,mscorlib.dll从.NET 2.0开始包含在System::Collections::Generic中的类,如Stack <>和Queue <>的类。 HashSet <>已添加到.NET 3.5的新程序集System.Core.dll中,他们不想修改2.0程序集。
因此,您必须添加对System.Core的引用,以避免出现错误消息。
当您遇到这样的错误时,请始终引用MSDN文档,这表明您需要程序集引用。
关于c++-cli - HashSet <T>在VS2012中哪里去了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13571277/