1

我正在尝试在结构构造函数中设置一个枚举,但我无法完全正确地获取语法。有什么建议吗?这就是我所拥有的,但我不断收到错误。

struct Event{
    enum eventType { Arrival, CPUburstCompletion, IOcompletion, TimerExpired }enumField;
    double time; // Defined as time units since the start of the simulation

    Event(eventType e, double theTime): enumField(e), time(theTime){}
};
4

2 回答 2

1

你试过这个吗?

struct Event{
    enum eventType { Arrival, CPUburstCompletion, IOcompletion, TimerExpired };

    eventType enumField;


    double time; // Defined as time units since the start of the simulation

    Event(eventType e, double theTime): enumField(e), time(theTime){}
};
于 2013-05-01T21:38:32.427 回答
1

也许...

struct Event {
  enum TYPE {
    Arrival,
    CPUBurstCompletion,
    IOCompletion,
    TimerExpired
  };
  double time;  
  TYPE type;  
  Event(Event::TYPE type, double time)
      : type(type),
        time(time) { }
};

int main() {
  Event e(Event::Arrival, 1.0);
  return 0;
}
于 2013-05-01T21:41:19.560 回答