C++ 尝试从std::runtime\u继承时发生编译错误

C++ 尝试从std::runtime\u继承时发生编译错误,c++,exception,C++,Exception,我试图在Ubuntu下用g++编译这个: #ifndef PARSEEXCEPTION_H #define PARSEEXCEPTION_H #include<exception> #include<string> #include<iostream> struct ParseException : public std::runtime_error { explicit ParseException(const std::string&

我试图在Ubuntu下用g++编译这个:

#ifndef PARSEEXCEPTION_H
#define PARSEEXCEPTION_H

#include<exception>
#include<string>
#include<iostream>

struct ParseException : public std::runtime_error
{
    explicit ParseException(const std::string& msg):std::runtime_error(msg){};
    explicit ParseException(const std::string& token,const std::string& found):std::runtime_error("missing '"+token+"',instead found: '"+found+"'"){};

};

#endif

我有这个问题已经有一段时间了,我真的看不出有什么问题:/

包括
你需要有一个
std::runtime\u error
的完整定义,可以从中得到

#include <stdexcept>
#包括

编译器通过其错误消息告诉您重要的事情。如果我们只接收第一条消息(从发生的第一条消息开始,逐个处理编译问题总是一件好事):

它告诉你看第9行。就在
“{”
之前的代码中有一个问题:类名无效。您可以由此推断编译器可能不知道“std::runtime\u error”是什么。这意味着编译器在您提供的头中没有找到“std::runtime\u error”。然后您必须检查是否包含了正确的头

在C++参考文档中的快速搜索将告诉您STD::RunTimeOrthError是标头,而不是>/Cord>。这是一个常见错误。

然后你必须添加这个头,错误就消失了。从其他错误消息中,编译器告诉你同样的事情,但是在构造函数中


学习阅读编译器的错误消息是一项非常重要的技能,以避免在编译问题上被阻止。

我们都在编辑您的签名。最好停止编写它。为我们省去一些麻烦。这是礼貌的。:-@Tomalak:那么有很多幼稚的用户,我只关心其中的个人部分这在全球范围内是可悲的。孩子气顽固地拒绝接受大众观点(
#include <stdexcept>
parseexception.h:9: error: expected class-name before ‘{’ token