Do we really need const?

Walter Bright newshound1 at digitalmars.com
Mon Sep 17 23:02:23 PDT 2007


Christopher Wright wrote:
> Most of the time, you shouldn't need to write those overloads. Either 
> the function can be const, in which case you can use it with mutable 
> data anyway, or it can't, in which case you can't write a const overload 
> for it. At least in an ideal system.

The reason that C++ member functions are written twice, const and 
non-const, are to transmit the const to the return type:

const T foo(const S);
T foo(S);

Nothing more.



More information about the Digitalmars-d mailing list