作者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