C++虚拟方法

Bit*_*map 2 c++

如果我创建一个结构:

struct joinpoint_exception: exception
{

   virtual const char* what () const throw ();
};
Run Code Online (Sandbox Code Playgroud)

what () const throw ()在这种情况下意味着什么?

Bil*_*eal 8

what是一个虚拟成员函数返回一个指向常量的指针,char它本身是常量并且不会抛出任何内容.

virtual const char* what () const throw ();
|-----| <- virtual member function
        |---------| <- returning a pointer to constant chars
                    |-----| <- named what
                            |---| <- which is constant
                                  |-------| <- which does not throw
Run Code Online (Sandbox Code Playgroud)

(从技术上讲,该函数仍然可以抛出,但如果确实如此,它会直接进入std::unexpected,默认为调用std::terminate)


Gre*_*ndt 5

what 是方法的名称

const 意味着该方法不会改变任何内部数据,除非它 mutable

throw ()意味着该方法不应抛出异常,如果它std::unexpected被抛出则代之