c++ - 错误 : ISO C++ forbids declaration of 'TimerExeption' with no type

标签 c++ exception

我在 timer.cpp 文件中尝试抛出 TimerException 类型的异常时遇到此错误。这是 timer_exception.h

  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   

这是我的 timer.cpp 文件,其中实例化了 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 }       

最佳答案

简单的错字。您的构造函数名称中缺少“c”。

13         TimerExeption(std::string message) : message(message) {}
//               ^^^

关于c++ - 错误 : ISO C++ forbids declaration of 'TimerExeption' with no type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15279132/

相关文章:

java - 获取数组长度时出错抛出异常

ios - 报告 iOS 中特定 Web 服务的应用程序崩溃和异常

Android - 获取异常

c++ - 专门化 hashmap 模板

c++ - 这个结构声明有什么问题?

Java Servlet 错误 - JasperReport(ClassNotFoundException : org. apache.commons.collections.ReferenceMap)

Javascript - 异常/错误数据类型?

c++ - 等待条件的非线程替代方法。 (编辑 : Proactor pattern with boost. asio?)

c++ - 部署 Visual Studio 项目

c++ - 获取和设置内部数据 : return type, 错误情况下的行为