C Please Explain S Wrong Following Code Whenever Try Call Main Get Error Saying Queuerear Q37067549

C++ Please explain what’s wrong with the following code.Whenever I try to call it in main, I get an error saying thatthis->queueRear is nullptr. How can I fix this.

Here is the source function

template <class Type>
void linkedQueueType<Type>::addQueue(const Type&newElement)
{
nodeType<Type> *newNode;
newNode = new nodeType<Type>; //create the node

newNode->info = newElement; //store the info
newNode->link = NULL; //initialize the link field to NULL

if (queueFront == NULL & queueRear == NULL) //if initiallythe queue is empty
{
queueFront = newNode;
       queueRear = newNode;
}
else //add newNode at the end
{
queueRear->link = newNode;
       queueRear =queueRear->link;
      
}
}

_______________

Here is the main i’m using to run it.

int main()
{
   linkedQueueType<int> *queueOne = newlinkedQueueType<int>();
   queueOne->addQueue(10);
  

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.