我嘗試在我的類中使用std :: map作爲屬性。我使用的是Visual Studio 2012,而我的類是這樣的:使用std :: map與指針
public ref class MyClass
{
std::map<std::wstring,MyType> * mpMyMap;
MyClass()
{
mpMyMap = new std::map<std::wstring,MyType>();
}
~MyClass()
{
delete mpMyMap;
}
Get(std::wstring name)
{
return mpMyMap[name];
}
}
At return mpMyMap [name];我得到錯誤,這種類型沒有運算符[]。我該怎麼辦?
爲什麼'mpMyMap'是一個指針?你需要它是一個指針嗎(你可能不會)。如果你需要它是一個指針,你應該使用一個智能指針類型來包裝它(比如'std :: unique_ptr'或'boost :: scoped_ptr')。 – Chad 2012-08-14 14:08:56
爲什麼在C++/CLI中使用std :: map?爲什麼不System :: Collections :: Generic :: Dictionary? – ForEveR 2012-08-14 14:22:24