0

这是警报类的定义:(我对问题进行了一些更改)

//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;”放在哪里,都会发生错误。

4

1 回答 1

0

我找到了原因。它似乎是由相互包含的头文件引起的(system.h&Alarm.h)。一旦我将“外部警报 *警报”放入 Alarm.cc,错误就会消失。但是我仍然没有找到有关该错误的更多详细信息。如果您能给我一些想法,我将不胜感激。

于 2020-05-26T12:33:22.720 回答