I have been working all day on not just this but 3 other assignments(for the same class) and this is the last issue I cannot figure out on my own, I am new with templates so not so sure as to how they work 100%.
Without templates this code runs perfectly, but with templates I am receiving a segmentation fault in the prioqueueUNS
file at the if(head == NULL)
and I cannot figure out why this is happening because I am defaulting head
to NULL
in the constructor, so any help would be very appreciated
int main
#include "node.h"
#include "prioqueueUNS.cpp"
int main() {
PrioQueueUNS<int> list;
list.insertItem(1);
}
node.h
#ifndef node_h
#define node_h
using namespace std;
template<class Type>
struct node {
Type data;
node<Type> *next;
};
#endif
prioqueueUNS.cpp
#ifndef prioqueueUNS_cpp
#define prioqueueUNS_cpp
#include "node.h
using namespace std;
template<class Type>
class PrioQueueUNS {
private:
node<Type> *head;
node<type> *tail;
int sizee;
int size;
int min;
public:
PrioQueueUNS() {
head = NULL;
tail = NULL;
}
PrioQueueUNS(Type *dataArray, int n) {
head = NULL;
tail = NULL;
}
void insertItem(Type n) {
node<Type> *temp;
temp->data = n;
temp->next = NULL;
if (head == NULL) { //<-- segment faulting when trying to access head
head = temp;
tail = temp;
min = n;
}
}
};