Live data from Hacker News

The Time Needed to Write “Effective Modern C++”

scottmeyers.blogspot.com

151–152 of 152 posts

Re: The Time Needed to Write “Effective Modern C++”

#151
post #79
post #42

Earlier quoted context omitted.

I agree that const is overall a good thing; however, it is tricky even in what you might think are simple cases. Take this for example: include void foo(const int& a, int& b) { std::cout Here the value of a changes in the middle of the function even though it's a const reference, because of aliasing. Here const doesn't mean the value won't change--only that you can't change it through that particular reference. Yes,…

You misunderstand reference-to-const, it does not imply that what "a" points to is immutable, it is a contract to the caller that foo will not use "a" in any non-const way.

That's exactly what I said; however, when you introduce people to C++ that seems rather counter-intuitive and can lead to a lot of mistakes. Yes, you can tell people "Well, you don't understand what the standard says!" but there's still something to be said for language features that don't take several pages to explain what they really do.

Re: The Time Needed to Write “Effective Modern C++”

#152
post #79

Earlier quoted context omitted.

You misunderstand reference-to-const, it does not imply that what "a" points to is immutable, it is a contract to the caller that foo will not use "a" in any non-const way.

That's exactly what I said; however, when you introduce people to C++ that seems rather counter-intuitive and can lead to a lot of mistakes. Yes, you can tell people "Well, you don't understand what the standard says!" but there's still something to be said for language features that don't take several pages to explain what they really do.

I just gave an explanation of reference-to-const in 1 sentence, not several pages. Also, my objection to your comment was your focus on what const means to foo() when the value is in what it means to main().
Post reply on HN