2016-03-03 42 views
3

這裏是我的full code,我自定義異常,如:寬鬆擲符爲 '虛擬爲const char * ro_err :: STDERR ::什麼()const的'

class StdErr : public std::exception { 

public: 
    str msg; 

    StdErr(str msg) { this->msg = msg; }; 

    virtual const char *what() const override { 
     return this->msg.c_str(); 
    }; 
}; 

和inherite它想:

class ShErr : public StdErr { 

public: 
    ShErr(str m) : StdErr(m) { } 
}; 

,並利用它們喜歡:

int main(int argc, char **argv) { 
    throw ro_err::ShErr("sh err"); 
    return (0); 
}; 

它提升looser throw specifier for ‘virtual const char* ro_err::StdErr::what() const’,我有以下問題:

  • 什麼更鬆散?
  • 什麼是說明者?
  • 如何解決它

回答

5

由於C++ 11 what()是noexcept。您尚未將其宣佈爲,但不包括。這就是「寬鬆投標說明者」告訴你的。見http://en.cppreference.com/w/cpp/error/exception/what

I.e.宣佈它像

virtual const char *what() const noexcept override 
+0

更寬鬆的是什麼意思? – asullaherc

+0

@asullaherc這是一個不太嚴格的throw規範的定義。沒有它,什麼()被允許拋出異常。 –

相關問題