Advancing the link in a linked list

Working on a double linked list problem. I'm trying to print out the items in the list, starting with a list consisting of a single node. I can't get the node to advance (I know that advancing on a one-node list will result in a NULL value, that' fine). I don't know how to pass the node to the function that advances it (called set_fore).

1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
    D_Node<int> test(1, NULL, NULL);
    D_Node<int> *head_ptr;
    D_Node<int> *tail_ptr;

    int entry = 1;
    head_ptr = &test;
    tail_ptr = &test;

    dlist_head_print_list(head_ptr);
}


dnode.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
template <class Item>
void dlist_head_print_list(D_Node<Item> *head_ptr)
{
    D_Node<Item> *this_ptr;
    this_ptr = head_ptr;

    while (this_ptr != NULL)
    {
        cout << this_ptr->data() << endl;
        this_ptr->set_fore(this_ptr);
    }
}

template <class Item>
void set_fore( D_Node<Item> *new_fore)
{
    link_fore = new_fore;
}


What am I doing wrong when I call set_fore. The compiler is telling me that "link_fore was not declared in this scope", so clearly set_fore is not getting the node correctly since link_fore is a member variable of the D_Node.

Thanks.

Looks like set_fore is supposed to be a D_Node member function, right?

In that case you need the D_Node scope qualifier:

1
2
3
4
5
template <class Item>
void D_Node::set_fore( D_Node<Item> *new_fore) // <- D_Node::
{
    link_fore = new_fore;
}





Thanks. Overlooked that one.
Topic archived. No new replies allowed.