What is the difference in these parameters?

I'm looking over some notes from class today and I come across some functions with parameters that I don't really understand.

void List::recursiveCopy(ListNode * & to, ListNode * const & from) const

What's the difference in "*&" and "* const &"?

When do functions need a const at the end of it?
What's the difference in "*&" and "* const &"?

One is a pointer passed by reference, the other is a pointer passed by reference-to-const. The body of recursiveCopy() is allowed to modify the value of to, e.g. to reassign it to point at another ListNode, but not allowed to modify the value of from.

When do functions need a const at the end of it?

When they don't modify any member objects of *this (or only modify the member objects labeled mutable)
Last edited on
Topic archived. No new replies allowed.