Generic Generics in Managed C++

只谈情不闲聊 提交于 2019-12-11 00:16:43

问题


I want to create a List of KeyValuePairs in a managed C++ project. Here is the syntax I'm using

List<KeyValuePair<String^, String^>^>^ thing;

but I'm getting the following error:

error C3225: generic type argument for 'T' cannot be 'System::Collections::Generic::KeyValuePair ^', it must be a value type or a handle to a reference type

I basically want to do this (C#)

List<KeyValuePair<string, string>> thing;

but in managed C++. Oh and in .Net 2.0. Any takers?


回答1:


KeyValuePair does not itself need to be a handle. Duh.

Because it's a value type, not a reference type (i.e. struct instead of class in C#).




回答2:


Figured it out:

List<KeyValuePair<String^, String^>>^ thing;

KeyValuePair does not itself need to be a handle. Duh.



来源:https://stackoverflow.com/questions/341477/generic-generics-in-managed-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!