s_member
개인 정적 변수를 생성자 또는 다른 멤버 함수에서 사용하고 수정하는 방법은 무엇입니까?클래스 생성자를 통해 private static 멤버 변수에 어떻게 액세스 할 수 있습니까?
이것은 내가 시도한 것입니다.
a.h :
#ifndef A_H
#define A_H
#include <set>
class A
{
public:
A();
virtual ~A();
private:
static std::set<int> s_member;
};
#endif
a.cpp : 당신은 A::s_member
을 선언했지만 아직 정의하지 않은
/tmp/ccBmNUGs.o: In function `A::A()': a.cpp:(.text+0x15): undefined
reference to `A::s_member' collect2: error: ld returned 1 exit status
참조의 정의를 찾을 수 없습니다 : http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how- do-i-fix – Mat
사용하려면 먼저 정의해야합니다. 방금 선언했습니다. 자세한 내용은 다른 의견의 링크를 참조하십시오. – celtschk