• Create Account

### #ActualCornstalks

Posted 04 February 2013 - 11:30 AM

You really shouldn't be memseting the data to zero. It'll wreck havock for more complex data types (for example, if it's a custom data type that initializes its members in some specific way, and you reset them to zero!). Not to mention, you're overflowing on your memseting:

memset(&this->first->data, 0, sizeof(sNode<Type>)); // data is a Type, not a sNode<Type>!


should be:

memset(&this->first->data, 0, sizeof(Type)); // But still, you shouldn't be doing this anyway


This can lead to all sorts of problems later on, like crashing.

You also want to change your do...while() loop in your deleter to be a while() loop (what if first->next is null?). Also, you're breaking your linked list. If you're deleting some node N, you need to set the previous node's next to be N->next. I won't completely rewrite it for you, as I want you to try.

Also, someday you'll want to implement the Rule of Three.

### #1Cornstalks

Posted 04 February 2013 - 11:28 AM

You really shouldn't be doing memseting the data to zero. It'll wreck havock for more complex data types (for example, if it's a custom data type that initializes its members in some specific way, and you reset them to zero!). Not to mention, you're overflowing on your memseting:

memset(&this->first->data, 0, sizeof(sNode<Type>)); // data is a Type, not a sNode<Type>!


should be:

memset(&this->first->data, 0, sizeof(Type)); // But still, you shouldn't be doing this anyway


This can lead to all sorts of problems later on, like crashing.

You also want to change your do...while() loop in your deleter to be a while() loop (what if first->next is null?). Also, you're breaking your linked list. If you're deleting some node N, you need to set the previous node's next to be N->next. I won't completely rewrite it for you, as I want you to try.

Also, someday you'll want to implement the Rule of Three.

PARTNERS