类 C++ 错误:"Virtual is not allowed"

Class C++ Error : "Virtual is not allowed"

本文关键字:is not allowed Virtual 错误 C++      更新时间:2023-10-16

我有一个我正在做的项目的标题:

#include<iostream>
#include<exception>
using namespace std;
class InvalidException : public exception
{
private:
    string message; 
public:

    InvalidException(const char *message)
    {
        this->message = message;
    }

    virtual const char *catch_the_error const throw()
    {
        return this->message.c_str();
    }
};

说明在这里不允许虚拟,我不知道为什么,因为我的例外是公开的。有人可以给我一个答案吗?

更改

virtual const char *catch_the_error const throw()

to

virtual const char *catch_the_error() const throw()
相关文章: