私はその原因を知っていますが、解決策はわかりません。`Scheduler :: _ singleton 'の多重定義で、ヘッダを2回インポートしています
私は、問題はそのother.cppにあるヘッダファイル
#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_ */
今すぐもちろん、私はScheduler.cpp
でこのヘッダファイルをインポートしているが、また別のファイルでother.cpp
小さなシングルトンクラスを持っていますどのように私はその周りに行く - 私は二度同じヘッダをインポートするので、私はそのを知っ
../otherfile.cpp:47: multiple definition of `Scheduler::_singleton'
を取得しておきますか? _singletone
は静的であり、静的なままでなければなりません。 そして、インクルードガードがどうして助けにならないのですか?
[この質問への回答](http://stackoverflow.com/questions/10340515/wunused-variable-warning)私は 'Scheduler :: _ singleton'の定義を実装ファイルに入れることを提案しました。私はそれが問題を解決すると思う。 – juanchopanza