这是警报类的定义:(我对问题进行了一些更改)
//Alarm.h
#pragma once
#include "system.h"
#include "list.h"
//#include "../machine/timer.h"
//void timerhandler(int dummy);
void check(int which);
class Alarm
{
public:
Alarm();
~Alarm();
void Pause(int howLong);
List *queue;
//Timer *timer;
int waiters;
void CheckIfDue(); // Check if an interrupt is supposed
// to occur now
static void new_instance();
static Alarm *instance;
};
alm 的声明位于名为 system.cc 的文件中。
//system.cc
#include "copyright.h"
#include "system.h"
...
Alarm *alm;
错误发生在 system.h 中,我在其中声明了 Alarm.h。
//system.h
#include "copyright.h"
#include "utility.h"
#include "thread.h"
#include "scheduler.h"
#include "interrupt.h"
#include "stats.h"
#include "timer.h"
#include "Alarm.h"
// Initialization and cleanup routines
extern void Initialize(int argc, char **argv); // Initialization,
// called before anything else
extern void Cleanup(); // Cleanup, called when
// Nachos is done.
extern Thread *currentThread; // the thread holding the CPU
extern Thread *threadToBeDestroyed; // the thread that just finished
extern Scheduler *scheduler; // the ready list
extern Interrupt *interrupt; // interrupt status
extern Statistics *stats; // performance metrics
extern Timer *timer; // the hardware alarm clock
extern Alarm *alm;
33 extern Alarm *alm;
../threads/system.h:33: error:expected initializer before ‘*’ token
似乎无论我把代码“extern Alarm *alarm;”放在哪里,都会发生错误。