Dear Friends:

I have the following issue: when I am trying to use the member variables of my header/trailer linked list, they are apparently not initialized. I, of course, am initializing the pointers in the class' constructor, but nonetheless they appear to not be making it out of the constructor. below is the code for my constructor and one of the member functions.

template <class Type>
HTlList<Type>::HTlList() {
node<Type> *header = new node<Type>;
node<Type> *trailer = new node<Type>;
header->next = trailer;
header->prev = NULL;
header->data = NULL;
trailer->next = NULL;
trailer->prev = header;
trailer->data = NULL;
count = 0;

template <class Type>
void HTlList<Type>::insert(const Type& insertItem) {
    node<Type> *newNode = new node<Type>; 
    newNode->data = insertItem;

    newNode->next = trailer;
    newNode->prev = trailer->prev;
trailer->prev->next = newNode;
trailer->prev = newNode;

    if(header->next == trailer) {
       header->next = newNode;

when debugging the program, i can see that the memory addressed are correct by the end of the constructor. But when i look at the values of trailer in the insert function, the pointer is set to memory address 0xcccccccc (junk). are the member variables out of scope for some reason? I have been trying to resolve this for almost a whole day.

Thanks in advance.


3 Years
Discussion Span
Last Post by daniel1977

Hi rubberman:

Thanks for your prompt reply. I figured it out late last night. I was redefining the trailer and header variables in the constructor, so their scope was only local to the constructor. And since I had the variables defined for the class before hand, the member functions were referring to the uninitialized variables.



This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.