Error no matching function for call to 'std::exception::exception(const char [15])'


Error no matching function for call to 'std::exception::exception(const char [15])'

Error 'logic_error' was not declared in this scope

錯誤原因

C++在使用VS 編譯時拋出異常可以用下列語句:

throw std::exception("XXX");

但使用Dev-C++ (GCC) 編譯時,會報以下錯誤:

Error no matching function for call to 'std::exception::exception(const char [15])'

解決方法:

#include <stdexcept>
throw std::logic_error("XXX");

如果不  #include <stdexcept>  則會報錯:

Error 'logic_error' was not declared in this scope

 

附:

標准異常階層體系

 





參考: 
http://www.cplusplus.com/forum/beginner/107744/
https://blog.csdn.net/xiajun07061225/article/details/8231270
https://blog.csdn.net/fengbingchun/article/details/78303734



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM