#exection handling

1 messages · Page 1 of 1 (latest)

forest doveBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

undone badger
#

These two code blocks are totally unrelated to each other, at least for me.

#

Maybe class members of sorted list and copyList function is what would have been even better

undone badger
#

Lemme look at simplified version

template <class T>
typename SortedList<T>::Node* SortedList<T>::copyList(Node* node) const {
    if (!node) return nullptr;

    Node* newNode = new Node(node->element);
    Node* current = newNode;
    node = node->next;

    while (node) {
        current->next = new Node(node->element);
        current = current->next;
        node = node->next;
    }
    return newNode;
}```
#

Ok so this does only throw when allocation fails, or am i missing something.

#

Seriously you need to simplify that, its so cryptic and unreadable for me, and will be for you given you come back to your project after a while

#

So anyways, that exception throwing type doesn't relate here

#

Would only if you derive the Node from it.

#

But still it's the pointers you're copying around not the Node object itself.

#

You're only allocating new memory that have a copy of the value contained in the old Node.