2013-10-27 3 views
0

정적 멤버 변수를 생성자 클래스에서 초기화하는 것이 적절합니까?정적 멤버 변수의 값을 초기화하는 적절한 장소

// CFoo.h 
class CFoo 
{ 
public: 
    CFoo(); 
    ~CFoo(); 
    static std::string str; 
}; 

// CFoo.cpp 
CFoo::CFoo() 
{ 
    str = "HELLO"; 
} 

CFoo::~CFoo() 
{ 
} 

감사

+0

http://stackoverflow.com/questions/185844/initializing-private-static-members –

답변

1

당신은 아직 define 정적 멤버 있습니다. CFoo.cpp에 정의해야합니다.

CFoo.cpp

std::string CFoo::str; // define str 

CFoo::CFoo() 

{ 
    str = "HELLO"; // reset str is fine 
} 

CFoo::~CFoo() 
{ 
} 
관련 문제