dequeue function in c++

hi,
im creating queue using linked list, the node has two data member in its private section now to dequeue a node from front, i have to move front pointer ahead and then delete the node having two data members, i wrote this:
int dequeue()
{
int x = front->get() ;
node *p = front ;
front = front->getnext() ;
delete p ;
size--;
return x ;

}
this didn't work b/c get will only return one data member

then i wrote this:

int dequeue()
{
int x = front->getname() ;
node *w =front->getage() ;
node *p = front ;
front = front->getnext() ;
delete p ;
delete w ;
size--;
return x ;

}
this also didn't work
the node private section:
class node
{
private:
string name ;
int age ;
node *nextnode ;
int size ;
what to do?
thanks
this didn't work b/c get will only return one data member


All right... then why not return a node copy, which has name and age?

1
2
3
4
5
6
7
8
9
10
11
12
node dequeue()
{
    node r = *front;
    node *p = front;

    r.setnext(0);
    front = front->getnext();
    p->setnext(0);
    delete p;
    --size; // same as size--; in this case
    return r;
}


Edit: mistake.
Last edited on
Topic archived. No new replies allowed.