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.


Recommended Answers

All 2 Replies

Please provide the full class definition (header file). This is not enough to really analyze your problem.

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.



Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.