unordered_map<std::string, std::string>* Accounts;
我有這個代碼在那裏從一個指針初始化,我可以只留下它的指針(*),我可以直接將值分配給它,但問題是,我使用C++ /在Visual Studio 2008中CLI和我不能在那裏類範圍簡單:如何在C++中初始化一個新的unordered_map <std :: string,std :: string> *(指針)?
定義一個變量,因爲它拋出這個錯誤:
error C4368: cannot define 'Accounts' as a member of managed 'Test::Login': mixed types are not supported C:\ Projects\Test\Login.h 32
所以,有人告訴我,我應該做一個指針,然後在初始化構造函數,但是如何從指針創建它? (我認爲像Accounts = new unordered_map) 我總是直接使用它。
我希望我已經夠清楚了。
@edit
public ref class Login: public System::Windows::Forms::Form
{
public:
unordered_map< std::string, std::string >* Accounts;
Test(void)
{
this->Accounts = new unordered_map<std::string, std::string>();
this->Accounts["hello"] = "test";
cout << this->Accounts["hello"];
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
它拋出這個錯誤:
Error 4 error C2107: illegal index, indirection not allowed C:\Projects\Test Login.h 37
提前感謝!
'Accounts = new unordered_map;'沒有工作或者什麼? –
Shahbaz
2012-03-29 13:10:20
'新的std :: unordered_map()'? –
hmjd
2012-03-29 13:10:35
我把一個@edit,並試圖設置一個值時,發生錯誤。 – Grego 2012-03-29 13:25:13