what does this function declaration mean in c++

前端 未结 11 1909
-上瘾入骨i
-上瘾入骨i 2020-12-24 13:12
virtual const char* what() const throw()
{

}

AFAIK it\'s a function that will return a constant pointer to a mutable char. The rest I am not sure.

11条回答
  •  孤城傲影
    2020-12-24 13:40

    1. virtual this one is used to overridden in derived class from base class
    2. const char* This is a pointer to a constant character
    3. what Returns a null-terminated character sequence that may be used to identify any exception
    4. throw() parameter inside the throw is empty so it will call std::unexpected for all exception
    #include
    #include
    
    class Myexception:public exception
    {
        virtual const char* what() const throw()
        {
            return "My exception here";
        }
    } myex;
    
    int main()
    {
        try() 
        {
            throw myex;
        }
        catch(exception &e)
        {
            cout<

提交回复
热议问题