The Stack

The class MStack is derived from the VMatrix class. The declaration is given by
class MStack: public VMatrix {

  private:

   int stackloc, level;
   MStack *next;
   VMatrix& Pop( void );

  public:

    MStack( void );
    void Push( VMatrix &ROp );

    void Inclevel();
    void Declevel();
    VMatrix &DecReturn( void ){
         Declevel();
         next->level = level;
         return * ((VMatrix *) this->next);
    }
    VMatrix &ReturnMat( void ){
         next->level = level;
         return * ((VMatrix *) this->next);
    }
    void Cleanstack( void );
    void PrintStack( void );
};

extern MStack *Dispatch;
Note the last line declares Dispatch as a pointer to a MStack object. It is also declared extern. The external declaration is used in the header file VIRT.H so that all modules will know that Dispatch exits, and will be created in the module containing the main program.

The MStack is a subclass of the VMatrix class, so it inherits the members and data of the VMatrix class, and has access to the protected part of the VMatrix class. The relationship is not strictly hierachical because the matrix class must call Dispatch to achieve some of its functions. I call it a symbiotic relationship, for whatever that's worth. The point to remember is that Dispatch must be instantiated as a global data object for its parent class to work.



Subsections