Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
m2mer opened this issue Apr 28, 2018 · 2 comments
Open

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

m2mer opened this issue Apr 28, 2018 · 2 comments

Comments

@m2mer
Copy link

m2mer commented Apr 28, 2018

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
Copy link

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

@CAHEK7
Copy link

CAHEK7 commented Jun 13, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants