A function that is a friend of class X has access to all of X's
private components. It is particularly useful for the I/O
operators >>; and <<; which work on istream&; and
ostream&; objects and so cannot be member functions of
your class. It is also useful for efficient access. Let's revisit
our linked list implementation of Istack, and see how simple
it becomes:
/////this is Stacks/mydefs2b.h
#include <new.h>
//////
class node { friendclass Istack; int data; node* next; node(int d, node* n); // constructor
};
class Istack { node* top;
public: void init(int Nitems = 100) { top = NULL; } void push(int x) { top = new node(x, top); } int pop();// Not defined here, later bool isempty() { return( top == NULL ); } bool isfull() { return( NULL ); }// Never Full
};