Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic Generics in Managed C++

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?

like image 212
Brian Avatar asked Oct 19 '25 08:10

Brian


2 Answers

Figured it out:

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

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

like image 55
Brian Avatar answered Oct 22 '25 01:10

Brian


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#).

like image 41
Konrad Rudolph Avatar answered Oct 22 '25 02:10

Konrad Rudolph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!