[Exceptional C++ Style] Exceptional C++ Style - Item 24:

White Wolf wolof at freemail.hu
Thu Jan 27 06:27:35 EST 2005


"Hammond, Peter" wrote:
> I was wondering about this in the context of coding
standards recently. In
> Exceptional C++ (item 43) Herb remarks that const on a
value parameter is
> pointless, and when I see it in a header it worries me: it
is a sign that
> someone may have misunderstood const, or pass-by-vlaue, or
both. On the
> other hand, having the constness of the argument enforced
in the
> implementaion can be very useful. The obvious way to solve
it is to leave it
> in the implemtation, but remove it from the definition, as
the guideline
> above. However, the difference between declaration and
definition would seem
> to be a source of confusion for many. Has anyone got any
experience of this
> kind of guideline and whether in practice it helps or
confuses?

You don't want to do that unless you are sure you won't need
to use those version of the Sun C++ compiler which (going
against the standard) count the constness of passed-by-value
arguments into the function signature - but only while
mangling the name.  They accept your (header non-const,
impl. const) function, it compiles, but it cannot link, as
the callers (who see the header only) will refer to the
function with a different name.

WW aka Attila



More information about the Effective-cpp mailing list