由于Visual Studio 2008(使用Windows窗体应用程序)上的C++/Cli,我使用了无序地图指针,但我无法为其指定值,抛出一个错误,因为我的代码示例展示给在创建实例后将值指定给unordered_map指针
//...
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"; // The Error is in this line, this is the line 37
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'是一个指针? – 2012-03-29 13:59:28
我这样做是因为在C++/CLI中,它们不允许你设置它而不用指针。 – Grego 2012-03-29 14:31:57