c++ - Why make a parameter const if you're going to do const_cast? -
there linked list example trying append node. part of code:
void append(listelement<t> const* ptr, t const& datum) { listelement<t>* temp = const_cast<listelement<t>*>(ptr); // ... }
what point in making ptr
pointer const
if you're going cast away? ptr
isn't used anywhere in function, temp
, wouldn't better make pointer non-const people know object might modified?
is there reason make parameter const
, const_cast
'ing away in body instead of making non-const?
what point in making
ptr
pointerconst
if you're going cast away?
none.
it breaks function contract , example of getting lost in code design.
to illustrate, this
- a: hey, can read object, read.
- b: okay, give me it, i'm going read it.
- b: writes on it
Comments
Post a Comment