C++ 错误:ISO C++;禁止声明';TimeReSeption';没有类型
尝试在timer.cpp文件中引发TimerException类型的异常时,出现此错误。这里是timer_异常C++ 错误:ISO C++;禁止声明';TimeReSeption';没有类型,c++,exception-handling,C++,Exception Handling,尝试在timer.cpp文件中引发TimerException类型的异常时,出现此错误。这里是timer_异常 1 #ifndef TIMER_EXCEPTION_H 2 #define TIMER_EXCEPTION_H 3 4 #include <iostream> 5 #include <string> 6
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
1\ifndef定时器\u异常\u H
2#定义计时器(异常)
3.
4#包括
5#包括
6.
7类时间异常{
8 friend std::ostream&operator简单的输入错误。构造函数的名称中缺少一个“c”
13 TimerExeption(std::string message) : message(message) {}
// ^^^
你的构造函数有一个typo.TimerExeption,缺少c。为什么你的异常类不继承自std::exception
?@BenjaminLindley:注意:它应该继承自std::exception
;但是它完全不能继承。@BillyONeal:是的,我理解。我只是想知道他不这么做的原因,或者如果他只是不知道他应该这么做。@BenjaminLindley我其实不知道有这样的事情,我会在我自己的时间调查,但这是学校的作业,所以我只是顺其自然。谢谢大家!
13 TimerExeption(std::string message) : message(message) {}
// ^^^