From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/CPLUSPLUS/EXAMPLES/inherit.cc | 116 ++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 reference/CPLUSPLUS/EXAMPLES/inherit.cc (limited to 'reference/CPLUSPLUS/EXAMPLES/inherit.cc') diff --git a/reference/CPLUSPLUS/EXAMPLES/inherit.cc b/reference/CPLUSPLUS/EXAMPLES/inherit.cc new file mode 100644 index 0000000..47365f9 --- /dev/null +++ b/reference/CPLUSPLUS/EXAMPLES/inherit.cc @@ -0,0 +1,116 @@ +/************************************************************************ + * + * Purpose: + * Author: M J Leslie + * Date: 26-Oct-98 + * + ************************************************************************/ + + +#include +#include // Instead of stdio.h + + +// ... The base class 'Fabric' +// ... is no different to normal. + + +class Fabric +{ +public: + + Fabric() {}; + ~Fabric(){}; + + SetSize(int x, int y) + { + Length = x; + Width = y; + } + + SetColour(char *C) + { + strcpy(Colour, C); + } + +private: + int Length; + int Width; + char Colour[20]; +}; + + + +// ... The derived class 'Tent' +// ... names 'Fabric' as a base class. + + +class Tent : public Fabric +{ +public: + + Tent() {}; + ~Tent() {}; + + SetNumOfPoles(int P) + { + Poles = P; + } + +private: + int Poles; +}; + + +// ... The derived class 'Clothes' also +// ... names 'Fabric' as a base class. + + +class Clothes : public Fabric +{ + public: + + Clothes() {}; + ~Clothes() {}; + + void SetNumOfButtons(int B) + { + Buttons = B; + }; + + int GetNumOfButtons(void) + { + return (Buttons); + }; + + private: + int Buttons; +}; + + +// ... Function definitions. + +void Init(Fabric &Material); + +main() +{ + Tent Frame; + Clothes Jacket; + + // ... Initialise using the derived methods. + + Init(Frame); + Init(Jacket); + + // .. Initialise using the unique methods. + + Frame.SetNumOfPoles(5); + Jacket.SetNumOfButtons(2); + +} + +void Init(Fabric &Material) +{ + Material.SetColour("Red"); + Material.SetSize (10, 20); +} -- cgit v1.2.3-54-g00ecf