ivanseidel / LinkedList

🔗 A fully implemented LinkedList made to work with general Microcontrollers and Arduino projects
MIT License
347 stars 120 forks source link

it is hard to judge get() success or not? #23

Open m2mer opened 6 years ago

m2mer commented 6 years ago

template T LinkedList::get(int index){ ListNode *tmp = getNode(index);

return (tmp ? tmp->data : T());

} no matter success or not, an instance of T is returned, so how to judge?

RyanAveryBSU commented 6 years ago

I'm confused. If there is no data, a new object is malloc'd and returned? or what is going on here...

CAHEK7 commented 5 years ago

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.