1
私はcppプロジェクト、cpp cliプロジェクト、およびc#winフォームプロジェクトを持っています。私は自分のネイティブcppプロジェクトにstd :: mapを持っています。どうすれば私のcliプロジェクトの.net dictonaryに変換できますか?Cpp/Cli std :: mapを.net辞書に変換する
私はcppプロジェクト、cpp cliプロジェクト、およびc#winフォームプロジェクトを持っています。私は自分のネイティブcppプロジェクトにstd :: mapを持っています。どうすれば私のcliプロジェクトの.net dictonaryに変換できますか?Cpp/Cli std :: mapを.net辞書に変換する
//Assuming dictionary of int/int:
#include <map>
#pragma managed
using namespace System::Collections::Generic;
using namespace std;
/// <summary>
/// Converts an STL int map keyed on ints to a Dictionary.
/// </summary>
/// <param name="myMap">Pointer to STL map.</param>
/// <returns>Dictionary of int keyed by an int.</returns>
/// <exception cref="ArgumentNullException">The <paramref name="myMap"/> parameter was a NULL pointer.
Dictionary<int, int>^ Convert(map<int, int>* myMap)
{
if (!myMap)
throw gcnew System::ArgumentNullException("myMap");
Dictionary<int, int>^ h_result = gcnew Dictionary<int, int>(myMap->size());
for (pair<int, int> kvp : *myMap)
{
h_result->Add(kvp.first, kvp.second);
}
return h_result;
}
あなたは何をしようとしていますか?どのようにあなたはそれをやろうとしましたか?どのように機能しませんでしたか? –
いいえ私はhavent 'は試みた。私は単純な方法があるかどうか疑問に思います。それぞれに対して –
と追加が最も簡単です –