Arrays &引用=';使用C+;将关联数组作为一个项在列表中重载运算符+/CLI
你们中的任何一位,请告诉我如何使用“=”运算符重载包含关联数组的列表。C++/CLI是我正在使用的laungauge 我想取得这样的成就Arrays &引用=';使用C+;将关联数组作为一个项在列表中重载运算符+/CLI,arrays,list,c++-cli,operator-overloading,associative,Arrays,List,C++ Cli,Operator Overloading,Associative,你们中的任何一位,请告诉我如何使用“=”运算符重载包含关联数组的列表。C++/CLI是我正在使用的laungauge 我想取得这样的成就 `myList[0]["Key"] = "1";` myList在哪里 System::Collections::Generic::List^myList 你们谁能给我一些线索吗 提前感谢, 彼得·约翰你为什么不直接使用List^ 该语法已经得到支持 但是,如果字典不能满足您的需要(例如,您需要一个trie结构而不是哈希表),索引器实现将如下所示: gene
`myList[0]["Key"] = "1";`
myList在哪里
System::Collections::Generic::List^myList
你们谁能给我一些线索吗
提前感谢,彼得·约翰你为什么不直接使用
List^
该语法已经得到支持
但是,如果字典不能满足您的需要(例如,您需要一个trie结构而不是哈希表),索引器实现将如下所示:
generic<typename T>
ref class AssociativeArray
{
// implementation details
// ...
public:
property T default[String^]
{
T get(String^ key)
{
T result;
if (!TryGetValue(key, result)) throw gcnew KeyNotFoundException(key);
return result;
}
void set(String^ key, T val)
{
SetValue(key, val);
}
}
};
通用
ref类关联数组
{
//实施细节
// ...
公众:
属性T默认值[字符串^]
{
无法获取(字符串^key)
{
T结果;
如果(!TryGetValue(键,结果))抛出gcnew KeyNotFoundException(键);
返回结果;
}
无效集(字符串^key,T val)
{
设置值(键,值);
}
}
};
为什么不直接使用列表^
该语法已经得到支持
但是,如果字典不能满足您的需要(例如,您需要一个trie结构而不是哈希表),索引器实现将如下所示:
generic<typename T>
ref class AssociativeArray
{
// implementation details
// ...
public:
property T default[String^]
{
T get(String^ key)
{
T result;
if (!TryGetValue(key, result)) throw gcnew KeyNotFoundException(key);
return result;
}
void set(String^ key, T val)
{
SetValue(key, val);
}
}
};
通用
ref类关联数组
{
//实施细节
// ...
公众:
属性T默认值[字符串^]
{
无法获取(字符串^key)
{
T结果;
如果(!TryGetValue(键,结果))抛出gcnew KeyNotFoundException(键);
返回结果;
}
无效集(字符串^key,T val)
{
设置值(键,值);
}
}
};