[問題] 'runtime_error' object or class?

看板C_and_CPP (C/C++)作者 (嫩b福)時間13年前 (2013/01/14 17:37), 編輯推噓2(203)
留言5則, 3人參與, 最新討論串1/1
第6.13.1 這章 第二個程式碼: if ( !item1.same_isbn(item2) ) throw runtime_error( "Data must refer to same ISBN" ); 小弟想請問一下 runtime_error 是 object 還是 class?? 底下有寫到: A throw takes an expression. In this case,that expression is an object of type runtime_error. 這句話說他是一個 object 沒錯吧? 但是6.13.3卻說runtime_error是一個class 背定義在<stdexcept>表頭... ps:書是第4版 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.37.160.33

01/14 18:10, , 1F
runtime_error 是 class , 然後你這兩個例子都是用到
01/14 18:10, 1F

01/14 18:11, , 2F
constructor,explicit range_error (const string& what);
01/14 18:11, 2F

01/14 18:16, , 3F
所以 throw 出去後,經過 ctor, 就變一個物件 (補清楚..)
01/14 18:16, 3F

01/14 19:44, , 4F
原來如此 謝謝分析!!
01/14 19:44, 4F

01/14 23:46, , 5F
「錯」是class。「這個錯」是object。
01/14 23:46, 5F
文章代碼(AID): #1Gyz7int (C_and_CPP)
文章代碼(AID): #1Gyz7int (C_and_CPP)