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

포인터에서 초기화하려면이 코드가 있어야합니다. 포인터 (*)를 그대로두면 값을 직접 할당 할 수 있지만 문제는 C++/단순 : 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

내가 포인터를 만든 다음에 초기화해야한다는 말을 들었다 :이 오류가 발생하기 때문에 비주얼 스튜디오 2008 CLI는 내가 클래스 범위

에서이 변수를 정의 할 수 없습니다 생성자를 만들지 만, 어떻게 포인터로 생성합니까? (나는 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

'new 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

관련 문제