如果我创建一个结构:
struct joinpoint_exception: exception
{
virtual const char* what () const throw ();
};
在这种情况下,what () const throw ()
是什么意思?
最佳答案
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
(从技术上讲,该函数仍然可以抛出,但如果抛出,它会直接转到 std::unexpected
,默认调用 std::terminate
)
关于C++虚方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6779531/