Object-Oriented Programming in C++(Part 2)

OOP (Part 2) As we've mentioned before, when a class is created, the constructor is called automatically. Further, we briefly discussed that the same name can be given to more than one function provided that some mechanism exists for telling the instances apart. As an example, consider the following:

class node
{
 public:
  node(int w) {winfo = w; pnext = this;}
  node(int w, node *p) {winfo = w; pnext = p;}
 private:
  int winfo;
  node *pnext;
};

Describe what each of the following does:

1) node head(5);

2) new node(1,0);

3) node *phead;
   phead = new node(1,0);
   phead = new node(2,phead);
Objects that have been created by new exist until they are disposed of using delete. The following code might be an example of disposing of a node:

node *pt=phead;
phead = phead->pnext;
delete pt;
A friend declaration within a class gives access to private members of the class to the friend. As an example, suppose that we declared everything in the class node to be private, but we wanted to use this class in conjunction with another class to create a stack that is pointer based and maintained as a circularly linked list. The declaration is as follows:

class node
{
  friend class stack;
  node(int w) {winfo = w; pnext = this;}
  node(int w, node *p) {winfo = w; pnext = p;}
  int winfo;
  node *pnext;
};


Problem: Write the rest of the code that implements a stack as a circularly linked list. The only functions that we will implement are:

1) Vinit
2) Vpush
3) Ipop
4) Iempty
5) Vprntstk


#include <stdio.h>

/*---------------------------------------------*/
class node
{
  friend class stack;
  node(int w) {winfo = w; pnext = this;}
  node(int w, node *p) {winfo = w; pnext = p;}
  int winfo;
  node *pnext;
};

class stack
{
  public:
    stack() {ptop = NULL;}
    void Vinit(void) {ptop=NULL;}
    void Vpush(int w);
    int Ipop(void);
    int Iempty() {return ptop==NULL;}
    void Vprntstk(void); 
  private:
    node *ptop;

};  

/*---------------------------------------------*/
void stack::Vpush(int w)
{
if(Iempty())
  ptop = new node(w);
else
{
  node *pt = new node(w,ptop->pnext);
  ptop->pnext = pt;
}
}
/*---------------------------------------------*/
int stack::Ipop(void)
{
  if(!Iempty())
  {
    node *pt = ptop->pnext;
    int w = pt->winfo;
    ptop->pnext = pt->pnext;
    delete pt;
    return w;
  }
}
/*---------------------------------------------*/
void stack::Vprntstk(void) 
{
  if(!Iempty())
    {
      printf("Stack Contains:\n");
      node *pt=ptop->pnext;
      while(pt != ptop)
	{
	  printf("value=%d\n",pt->winfo);
	  pt = pt->pnext;
	}
      printf("value=%d\n\n",pt->winfo);
    }
}


/*---------------------------------------------*/
void main(void)
{
stack clstk;
clstk.Vpush(1);
clstk.Vpush(2);
clstk.Vpush(3);
clstk.Vpush(4);
clstk.Vprntstk();
clstk.Ipop();
clstk.Ipop();
clstk.Vprntstk();

}
There is at least one significant error in the above program. Any ideas??!!