Jump to content

Const (computer programming)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Wlievens (talk | contribs) at 15:04, 23 March 2005 (initial page). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Const correctness is a programming language feature, its most famous implementor being C++. In languages supporting this feature, variables can be said to be 'const'. When a const object is referenced, only the methods declared as const may be called. This allows programmers to formalise a specific design contract: they can promise at compile-time that a parameter of a function cannot be modified destructively.

Of course, const methods can only call other const methods, and cannot assign member variables