我很好奇C++/CLI中Collections :: Generic :: Dictionary 类的声明语法。C++/CLI通用::字典声明语法
通常我们在一个类中声明的引用,并初始化:
public ref class CDemo {
private: ClassA^m_InstanceA;
// Why the absence of '^'.
private: Dictionary<int, int> m_Dic;
CDemo() :
m_InstanceA(gcnew ClassA()),
m_Dic(gcnew Dictionary<int, int>())
{...}
};
可能有人请解释为什么要“^”缺席呢?
更重要的是,如果我使用的TValue另一个字典, 上面的字典我要声明的是这样的:
Dictionary<T, Dictionary<T, T>^ > m_Dic; // A '^' in the TValue parameter, which is
// normal, but same question as above,
// I don't have to declare m_Dic as^?
感谢。
这是一个错误。查看构造函数生成的IL,注意如何创建两个字典。 – 2010-12-06 17:23:37