简体   繁体   English

错误:ISO C ++禁止无类型的'TimerExeption'声明

[英]error: ISO C++ forbids declaration of 'TimerExeption' with no type

I'm getting this error when trying to throw an exception of type TimerException in my timer.cpp file. 尝试在timer.cpp文件中引发类型为TimerException的异常时出现此错误。 here is timer_exception.h 这是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   

and here is my timer.cpp file where the TimerException is being instantiated 这是我的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 }       

Simple typo. 简单的错字。 You're missing a 'c' in your constructor's name. 您在构造函数名称中缺少“ c”。

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

Your constructor has a typo. 您的构造函数有一个错字。 TimerExeption, the c is missing. TimerExeption,c丢失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM