[英]error: ISO C++ forbids declaration of 'TimerExeption' with no type
嘗試在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) {}
// ^^^
您的構造函數有一個錯字。 TimerExeption,c丟失。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.