약간의 문제가 있습니다. 그 원인은 알지만 해결책은 없습니다. `Scheduler :: _ singleton '의 다중 정의, 두 번 헤더 가져 오기
나는 그 헤더 파일 작은 싱글 톤 클래스가#ifndef SCHEDULER_H_
#define SCHEDULER_H_
#include <setjmp.h>
#include <cstdlib>
#include <map>
#include <sys/time.h>
#include <signal.h>
#include "Thread.h"
class Scheduler {
public:
static Scheduler * instance();
~Scheduler();
int threadSwitcher(int status, bool force);
Thread * findNextThread(bool force);
void runThread(Thread * nextThread, int status);
void setRunThread(Thread * thread);
void setSleepingThread(Thread * thread);
void setTimer(int num_millisecs);
std::map<int, Thread *> * getSuspendedThreads() const;
std::map<int, Thread *> * getReadyThreads() const;
Thread * getSleepingThread() const;
Thread * getRunningThread() const;
Thread * getThreadByID(int tid) const;
const itimerval * getTimer() const;
const sigset_t * getMask() const;
void pushThreadByStatus(Thread * thread);
Thread * extractThreadByID(int tid);
private:
Scheduler();
sigset_t _newMask;
sigjmp_buf _image;
static Scheduler * _singleton;
std::map<int, Thread *> * _readyThreads;
std::map<int, Thread *> * _suspendedThreads;
Thread *_sleepingThread;
Thread * _runThread;
itimerval _tv;
};
Scheduler * Scheduler::_singleton = 0;
#endif /* SCHEDULER_H_ */
지금은뿐만 아니라 다른 파일 other.cpp
문제에 Scheduler.cpp
이 헤더 파일을 가져 물론입니다 other.cpp에서 나는 계속 간다.
../otherfile.cpp:47: multiple definition of `Scheduler::_singleton'
내가 같은 머리글을 두 번 가져 오기 때문에 나는 그것을 안다. 나는 그것을 어떻게 돌리 느냐? _singletone
은 정적이며 고정 된 상태 여야합니다. 그리고 포함 경비원이 어떻게 도움이되지 않습니까?
[이 질문에 대한 답변] (http://stackoverflow.com/questions/10340515/wunused-variable-warning) 구현 파일에'Scheduler :: _ singleton'의 정의를 넣는 것이 좋습니다. 나는 그것이 문제를 해결할 것이라고 생각한다. – juanchopanza