1
다음 클래스의 ID를 추적하기 위해 정적 멤버 변수 id_index를 사용하여 "Person"클래스를 만들려고합니다. 동일한 ID). 나는이 프로그램을 실행하면 나는 이러한 오류를 얻을 :클래스 ID를 추적하기 위해 ID 정적 멤버 변수 만들기
이G:\WorkSpace\Human\Debug/../Person_Class/Person.cpp:11: multiple definition of `Person::id_index'
Person_Class\Person_Set.o:G:\WorkSpace\Human\Debug/../Person_Class/Person_Set.cpp:10: first defined here
Human.o: In function `main':
G:\WorkSpace\Human\Debug/../Human.cpp:16: multiple definition of `Person::id_index'
Person_Class\Person_Set.o:G:\WorkSpace\Human\Debug/../Person_Class/Person_Set.cpp:10: first defined here
이것은 person.h 파일입니다
#ifndef PERSON_H_
#define PERSON_H_
#include <iostream>
class Person {
public:
static unsigned int id_index; // will aut0-set to 0
Person();
};
unsigned int Person::id_index = 0;
#endif /* PERSON_H_ */
person.cpp : 인간의 내부에 저장된
Person::Person(): ID(id_index) {
}
주요 기능입니다. cpp :
int main(){
Person michael;
return 0;
}