Re: [問題] 谷哥coding style的學習

看板C_and_CPP (C/C++)作者 (改)時間13年前 (2012/12/04 23:16), 編輯推噓2(205)
留言7則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《rosemary0401 (rosemary)》之銘言: : 最近再看google的coding style : http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml : 有些地方不是很懂 : <Question 3> : Names and Order of Includes : Use standard order for readability and to avoid hidden dependencies: C : library, C++ library, other libraries' .h, your project's .h. : 這樣規定的好處是什麼呢?

11/13 04:34,
q3 另一個用意是把較可靠的放前,較不可靠的放後。
11/13 04:34

11/13 04:35,
不然自己寫錯的時候可能錯誤訊息會出現在 std header 上,
11/13 04:35

11/13 04:35,
因為你自己寫的 header 漏了什麼,造成往下炸過去。
11/13 04:35

11/13 04:36,
弄不清楚狀況的人,可能以為是 std header 有 bug...
11/13 04:36
不是很懂為什麼錯誤的訊息會出現在別的header裡?? 有人可以用sample code舉例一下,在什麼情況下,A.h的錯誤訊息會出現在B.h裡嗎?? <New Question 1> Forward Declarations Cons: * It can be difficult to determine whether a forward declaration or a full #include is needed for a given piece of code, particularly when implicit conversion operations are involved. In extreme cases, replacing an #include with a forward declaration can silently change the meaning of code. 若牽涉到隱式轉換的話,為什麼會難以決定到底要用#include或forward declaration呢? 而且用forward declaration來代替#include,為什麼會改變code的意思呢?? <New Question 2> Copy Constructors Decision: Few classes need to be copyable. Most should have neither a copy constructor nor an assignment operator.... 這裡提到只有少數的class有copy的需求, 這就是為什麼c#和java會把class設為reference type, 而不是像C\C++一樣把class設為value type的原因嗎??? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.153.199

12/04 23:17, , 1F
最前的問題 例如用到 template 的程式碼
12/04 23:17, 1F

12/05 01:46, , 2F
或是class結尾漏了分號 XD
12/05 01:46, 2F

12/05 02:44, , 3F
Q1: Forward decl.定出來的class是個incomplete type.
12/05 02:44, 3F

12/05 02:45, , 4F
而incomplete type因為看不到class body, 會造成
12/05 02:45, 4F

12/05 02:46, , 5F
template取代失敗, 啟動SFINAE機制
12/05 02:46, 5F

12/05 02:46, , 6F
12/05 02:46, 6F

12/05 02:47, , 7F
12/05 02:47, 7F
文章代碼(AID): #1GlXFFWH (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1GlXFFWH (C_and_CPP)