Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • 1
    Up vote because you explain that final and const do not have the same guarantees. Commented Oct 5, 2016 at 4:31
  • 3
    Constness is about writeability, not about mutability. Commented Oct 5, 2016 at 9:45
  • 6
    What happens if you write to a const reference? A compile time error. What happens if you write to the object that is referenced somewhere by const reference via another non-const reference? It mutates. Immutable object can't mutate, hence const refernce does not necessarily reference immutable object. Commented Oct 5, 2016 at 15:45
  • 1
    @Basilevs your observation only applies with const refs. If an object itself is declared const (not just the reference) then it it is more-or-less immutable (unless someone nefariously casts away the constness). Commented Nov 8, 2016 at 5:36
  • 1
    @Snowman an object can very definitely be const. const int i = 1; is an object that is neither a reference nor a pointer, and it is const Commented Aug 30, 2017 at 8:41