How do I return the data in the last node from the RemoveTail function? Currently I have something like below.This is a basic doubly linked list.

class List;
class Node {

    Node* next;
    Node* prev;
    void* data;

    public:

        Link( void* pData ) :
            next( 0 ), prev( 0 ), data( pData )
        {}

    friend class List;
};


class List {

    Node* head;
    Node* tail;

    public:

        List() :
            head( 0 ), tail( 0 )
        {}

        void* RemoveTail();
        //more funtions...
};

void List::RemoveTail() //removes last node & returns pointer to object contained in it
{
    if(tail == head)
    {
        void* data = tail->data; //This didn't work
        delete tail;
        head = tail = 0;
        return data;
    }
    else 
    {
    //code
    }
}

The void* data = tail->data; isn't working. Is there any other way to do this?

The void* data = tail->data; isn't working.

What do you mean by "isn't working"? The code you posted clearly isn't your actual code, so I can't say for sure what the problem is.

Damn silly mistake lol. Nevermind. Thanks anyway :)

Be a part of the DaniWeb community

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