header file I am using, teacher provided it so I doubt the error lies in here but it's throwing the unhandled exception
template<class ItemType>
class Node
{
private:
ItemType item;
Node<ItemType> *next;
public:
Node(); //default constructor
Node(const ItemType &anItem); //none default constructor #1
Node(const ItemType &anItem, Node<ItemType> *nextPtr); //none default constructor #2
void setItem(const ItemType &anItem);
void setNext(Node<ItemType> *nextPtr);
ItemType getItem() const;
Node<ItemType> *getNext() const;
};
/*other functions*/
template<class ItemType>
Node<ItemType>* Node<ItemType>::getNext() const {
return next;
}
The function that I am getting in trouble with is this one (I tested all prior functions which worked fine).
bool getNextUnvisitedCity(char citeh, char &adjCity){
if(!(isInMap(citeh)))
return false;
else {
for(int i=0; i<9; i++){
if(flightMap[i].city_name==citeh){
if(flightMap[i].adjacent_city=NULL)
return false;
Node<char>* tempPtr;
tempPtr=flightMap[i].adjacent_city;
while(tempPtr->getNext()!=NULL){
if(!(isVisited(tempPtr->getItem()))){
adjCity=tempPtr->getItem();
return true;
}
else
tempPtr=tempPtr->getNext();
}
if(flightMap[i].adjacent_city->getNext()!=NULL){
if(!(isVisited(flightMap[i].adjacent_city->getItem()))) {
adjCity=flightMap[i].adjacent_city->getItem();
return true;
} else
return false;
} } } } }
the error I'm getting is
Unhandled exception at 0x00fe4a76 in Assignment 12.exe: 0xC0000005: Access violation reading location 0x00000004
and the specific error is this | 0x00000000 {item=??? next=??? } | const Node<char> * const
I failed my test because of the SAME exact thing but I'm not doing anything incorrectly! I've been scraping my way across the internet for information why this is happening but I am not getting any reason why