LinkedList
LinkedList copied to clipboard
it is hard to judge get() success or not?
template<typename T> T LinkedList<T>::get(int index){ ListNode<T> *tmp = getNode(index);
return (tmp ? tmp->data : T());
} no matter success or not, an instance of T is returned, so how to judge?
I'm confused. If there is no data, a new object is malloc'd and returned? or what is going on here...
If there is no data, a new object of type T is default-constructed and returned. For simple types like int\char it won't allocate memory, just put zero value into some register and return.