C가

2017-12-15 10 views
0

내가 너무C가

#ifndef MYAPP 
#define MYAPP 
#include <map> 
namespace MyApp{ 
    class MyClass{ 
     private: 
      static std::map<int, bool> SomeMap; 
     public: 
      static void DoSomething(int arg); 
    }; 
} 
#endif MYAPP 

같은 헤더 파일과 implemtation 파일

#include "Header.h" 
#include <map> 
namespace MyApp{ 
    void MyClass::DoSomething(int arg){ 
     if(MyClass::SomeMap[5]){ 
      ... 
     } 
    } 
} 

나는 그것을 컴파일을 시도해야, 그것은 나에게 오류 클래스를 제공합니다 "MyClass"에는 "SomeMap"회원이 없습니다. 이 문제를 어떻게 해결할 수 있습니까?

#include "Header.h" 
#include <map> 
namespace MyApp{ 
    std::map<int, bool> MyClass::SomeMap; 

    void MyClass::DoSomething(int arg){ 
     if(MyClass::SomeMap[5]){ 
      ... 
     } 
    } 
} 

추신 :

+1

[정적 클래스 멤버에 대한 정의되지 않은 참조] (https://stackoverflow.com/questions/272900/undefined-reference-to-static-class-member)의 가능한 복제본 – user4581301

답변

1

당신은 정적 변수를 정의하는 잊어 버린 클래스 정의 후 예제 코드에 ;이 누락되었습니다.