1
我在尝试在我的timer.cpp文件中抛出TimerException类型的异常时出现此错误。这里是timer_exception.h错误:ISO C++禁止声明没有类型的'TimerExeption'
1 #ifndef TIMER_EXCEPTION_H
2 #define TIMER_EXCEPTION_H
3
4 #include <iostream>
5 #include <string>
6
7 class TimerException{
8 friend std::ostream &operator <<(std::ostream &os, const TimerException e){
9 std::cout << " *** TIMER EXCEPTION *** " << e.message;
10 return os;
11 }
12 public:
13 TimerExeption(std::string message) : message(message) {}
14 private:
15 std::string message;
16 };
17
18
19 #endif
和这里就是TimerException被实例化
1 #include <ctime>
2 #include "timer.h"
3 #include "timer_exception.h"
4
5 void Timer::start(){
6 if(timer != 0) throw TimerException("Timer already started");
7 this->timer = clock();
8 }
为什么您的异常类不会从'std :: exception'继承? – 2013-03-07 18:42:43
@BenjaminLindley:注意:它应该从'std :: exception'继承;但是完全有效的不是。 – 2013-03-07 18:47:08
@BillyONeal:是的,我明白这一点。我只想知道他的理由是不是这样做,或者他根本不知道他应该这样做。 – 2013-03-07 18:48:51