There was a linked list example where someone was trying to append a node. This is part of the code:
void Append(ListElement<T> const* ptr, T const& datum)
{
ListElement<T>* temp = const_cast<ListElement<T>*>(ptr);
// ...
}
What is the point in making ptr
a pointer to const
if you're going to just cast it away? ptr
isn't used anywhere in the function, just temp
, so wouldn't it be better to make it a pointer to non-const so people know that the object might be modified?
Is there a reason to make a parameter const
and then const_cast
'ing it away in the body instead of just making it non-const?