Can someone explain why the function arguments for AppendNode() are pointers to shared_ptrs, and the arguments for MergeSortedLists() are just shared_ptrs? Why can’t both just have arguments to shared_ptrs?
Cheers
Can someone explain why the function arguments for AppendNode() are pointers to shared_ptrs, and the arguments for MergeSortedLists() are just shared_ptrs? Why can’t both just have arguments to shared_ptrs?
Cheers
append_node needs to modify the head and tail pointers themselves, that’s why they are passed by reference not by value. They could be passed as shared_ptrs<…> &tail, which is a style you may be familiar with. However it is usually considered good style to pass an argument by reference through pointers and not through the &operator.