For some reason when doing anything with my linked lists I am getting a seg-fault. All of my linked list functions check to see if the head is NULL before adding or doing anything in the list to prevent seg-faults but for some reason that check in itself is causing the seg fault. Hopefully my code can clarify that...
Code:
void Laundry::addClean(Clothing c){
if(c_head == NULL){
c_head = new node<Clothing>(c, NULL);
}
else
{
c_tail->setLink(new node<Clothing>(c, NULL));
c_tail = c_tail->link();
}
clean++;
}
that is where I am getting the seg-fault... and in any other function that uses if(some_head == NULL). in my last project I was having this same problem and it was because I had typed if(some_head = NULL). this time tho I have no idea what is wrong. My pointer is declared in laundry.h like this:
Code:
private:
node <Clothing> * c_head;
node <Clothing> * c_tail;
And my template node class:
Code:
template <class T>
class node{
public:
node(){linkfield = NULL;}
node(T d, node *lf){datafield = d; linkfield = lf;}
T data(){return datafield;}
node * link(){return linkfield;}
void setData(T d){datafield = d;}
void setLink(node *lf){linkfield = lf;}
private:
T datafield;
node *linkfield;
};
I've been at this for a while so maybe it's just something I'm not seeing and a fresh set of eyes will help. At any rate thanks for looking