Era*_*ran 1 c++ oop exception class
I am trying to overriding exception method, std::exception::what(), to make customized exception message.
The compiler says, "Exception specification of overriding function is more lax than base version", about this section:
class diffSizeExp : public std::exception
{
public:
    const char* what() const override {
    }
};
When switching the 'override' with 'noexcept' like this:
    class diffSizeExp : public std::exception
{
public:
    const char* what() const noexcept {
    }
};
It is working. However, I could not understand the different between those too, because I do want to overriding the standard method. From my knowledge, 'noexcept' means - don't throw exception, not overriding a method.
It would be appreciate if you could explain me in manners of Code efficiency and correctness. Is it the right way to handle this problem? Why does overriding not possible?
Thanks.
你需要
class diffSizeExp : public std::exception
{
public:
    const char* what() const noexcept override {
    }
};
要么
class diffSizeExp : public std::exception
{
public:
    const char* what() const noexcept {
    }
};
简单来说,const和noexcept是函数限定符。如果更改了这些内容,则不会覆盖函数,而是创建了重载(void foo()并且void foo() const与void foo()和一样void foo(int))。
但是,override不是功能限定符。它只是一个帮助器关键字,当您实际上没有覆盖虚拟函数时,使编译器抛出错误。它是可选的,只是为了帮助您发现潜在的错误(强烈建议在每个虚函数中使用它)。