const and call by value parameters



I have a function

void myobject::g (double d)
{
dval = d;
}

Now function g() doesn't modify it's local copy of d in any way, therefore
it should be declared as

void myobject::g (const double d) {}

The thing is, I find that the vast majority of my call by value parameters
aren't reused within their functions, therefore I find that I have an awful
lot of function parameters using the const modifier.

When I look at other code, in books or in libraries, you don't tend to see
const littered throughout the code, even in functions that don't modify
their value parameters.

Am I missing something here?

--
Best regards
Mark


.



Relevant Pages

  • RE: const and call by value parameters
    ... "Mark" wrote: ... > void myobject::g ... you omit const in this case. ... MUST NOT modify its parameter, rather than when it DOESN'T modify ...
    (microsoft.public.vc.language)
  • Code critique please
    ... struct SortOrder1: SortOrder ... bool operator()(const A &lhs, const A &rhs) ... class Mark ... void Tree::Insert ...
    (comp.lang.cpp)
  • Re: const and call by value parameters
    ... >> void f ... > I agree with you, but if you declare those parameters with const, you can ... > I use const as Mark do, and it's true that it could make more difficult ... but I think it's good to avoid code like showed above. ...
    (microsoft.public.vc.language)
  • Re: MSDN const_cast sample
    ... void f(const int* const p) ... other function calls, even though it's declared const, and thus must ... modify() can change the value of *p through g_theRealVariable (since ...
    (microsoft.public.vc.language)
  • Re: const and call by value parameters
    ... >Now function gdoesn't modify it's local copy of d in any way, ... >void myobject::g ... >lot of function parameters using the const modifier. ...
    (microsoft.public.vc.language)