0
node *temp; 
temp->dataItem = newPassenger;
if(size == 0)
{
    Head = temp;
    Tail = temp;
}
else
{
    Tail->nextNode = temp;
    Tail = temp;
}
size++;

I need help as VS keeps saying that temp is not initialized, I have little experience with C++. My node class is as follows

#include "passenger.h"
#pragma once
class node
{
public:
    node();
    passenger dataItem;
    node * nextNode;
};
2
  • What kind of help are you looking for? temp is in fact not initialized. Commented Feb 25, 2013 at 4:07
  • You declared a pointer. You did not make it point to anything before you used it. You did not allocate any nodes for it. Commented Feb 25, 2013 at 6:32

3 Answers 3

1
node *temp = new node; 
temp->dataItem = newPassenger;
if(size == 0)
{
    Head = temp;
    Tail = temp;
}
else
{
    Tail->nextNode = temp;
    Tail = temp;
}
size++;
Sign up to request clarification or add additional context in comments.

Comments

1

You should read more introductory C++ books. This usually gets covered pretty early.

You should write

node *temp = new node;

This will reserve the space for a node in memory. When you're done with this node, you should write

delete temp;

You must make sure you don't delete something twice, because this will cause your program to crash.

Comments

0
node *temp; 
temp->dataItem = newPassenger;

If the above is really your code, then the compiler's quite right - you're deferencing temp without having initialised it. You probably want something like this:

node* temp = new node;
temp->dataItem etc...

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.