#include <iostream.h> class A { public: virtual void f () { cout << "A::f" << endl; g ();} virtual void g () { cout << "A::g" << endl; } void h () { cout << "A::h" << endl; } }; class B : public A { public: void f () { cout << "B::f" << endl; } void g () { cout << "B::g" << endl; h (); } void h () { cout << "B::h" << endl; } }; class C : public B { public: void f () { cout << "C::f" << endl; } void g () { cout << "C::g" << endl; } void h () { cout << "C::h" << endl; f(); } }; void P ( A * pa, B * pb ) { pa->f (); pa->g (); pa->h (); pb->f (); pb->g (); pb->h (); delete pa; delete pb; } int main () { P ( new B, new B ); cout << "------------------------------" << endl; P ( new C, new C ); return 0; }
GENERIC TYPE T IS PRIVATE; SIZE : INTEGER; PACKAGE Stacks IS TYPE Stack IS LIMITED PRIVATE; PROCEDURE Push ( S: IN OUT Stack; X : IN T ); PROCEDURE Pop ( S: IN OUT Stack; X : OUT T ); FUNCTION IsEmpty ( S : IN Stack ) RETURN BOOLEAN; FUNCTION IsFull ( S : IN Stack ) RETURN BOOLEAN; PRIVATE TYPE Stack is RECORD Body : ARRAY ( 1..SIZE ) OF T; Top : INTEGER := 1; END RECORD; END Stacks;