2012-03-29 13 views
1
unordered_map<std::string, std::string>* Accounts; 

私はこのコードをポインタから初期化するために、ポインタ(*)を残しておけば、直接値を割り当てることができますが、問題は私がC++/Visual Studio 2008のCLIと、それは、このエラーがスローされますので、私はクラスのスコープシンプル:新しいunordered_map <std :: string、std :: string> *(ポインタ)をC++で初期化する方法は?

であり、変数を定義することはできません。

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

感謝を!

+0

'Accounts = new unordered_map ;'は機能しませんでしたか? – Shahbaz

+0

'新しいstd :: unordered_map ()'? – hmjd

+0

@editを入れて、その中に値を設定しようとしたときにエラーが発生したことを知らせます。 – Grego

答えて

2
unordered_map<std::string, std::string>* Accounts = new unordered_map<std::string, std::string>(); 

完了したら、削除する必要があることを覚えておいてください。

delete Accounts; 
+0

あなたのクラスをコピー不可能にしたり、適切なコピーセマンティクスを追加したり(C++ 11で移動する)必要があります。 –

+0

@editを入れて、値を設定しようとしているときにエラーを表示します。 – Grego

関連する問題