我認爲「常量正確性」的概念非常明確,但是當我和其他人談論這個概念時,似乎我們對它的含義有不同的想法。有些人說這是關於一個在儘可能多的地方有「const」註解的程序。其他人定義一個程序爲const-correct,當且僅當沒有違反使用常量註釋的常量時(即它是編譯器檢查你的屬性)。const-correctness的定義是什麼?
所以我想知道,它的這些功能是const正確性:
struct Person {
string getName1() const { return _name; }
string getName2() { return _name; }
string getName3() const { _name = "John"; return _name; }
string getName4() { _name = "John"; return _name; }
string _name;
};
我在網上搜索了相關定義上,但不能真正找到明確的答案,我也有懷疑可能會出現citogenesis的情況。那麼任何人都可以爲定義提供任何堅實的引用?
getName3不會編譯,所以跳過那個。 –
[什麼是「const正確性」?](http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.1) – cpx
http://stackoverflow.com/questions/228783/什麼是關於使用下劃線在交流標識符 – Flexo