作者dxi (D差耶)
看板EE_DSnP
標題[問題] const
時間Sun Apr 12 23:18:19 2009
觀念不大清楚,煩請老師與各位同學指教:
Passed in a reference to a constant object ‘c’
'c' cannot be modified in the function
↓
const A& B::blah (const C& c) const{...}
↑ ↑
Return a reference to a ↑
constant object ↑
→ The returned object can ↑
then only call
constant methods ↑
↑
This is a constant method, meaning this object is
treated as a constant during this function
→None of its data members can be modified
請問上述的const method是指傳回主程式的物件是const嗎?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.4.234
1F:推 timrau:如果你是說最右邊那個const, 否。 04/12 23:27
2F:→ timrau:它是指"這個function裡面不會變動caller的member data" 04/12 23:28
3F:→ timrau:最左邊的const才是管return value 04/12 23:29
4F:→ dxi:謝謝! 04/13 01:23