class Amphibian
1: /** @file amphibian.hpp
2: Based on an example from N. Josuttis, Object-Oriented Programming in C++.
3: */
4:
5: #include "car.hpp"
6: #include "boat.hpp"
7:
8: namespace Josuttis
9: {
10: class Amphibian : public Car, public Boat
11: {
12: public:
13: Amphibian
14: (
15: int kilometers = 0, //in
16: int milesAtSea = 0 //in
17: )
18: : Boat(milesAtSea),
19: Car(kilometers)
20: /*
21: Note that constructors are called in the order of their
22: declaration in the class header, not in the order in which
23: they appear in the initialization list, which is irrelevant.
24: So, for example, in this case the Car constructor is called
25: first, followed by the Boat constructor.
26: */
27: {
28: cout << "\nAmphibian constructor called.";
29: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
30: }
31:
32: virtual ~Amphibian()
33: {
34: cout << "\nAmphibian destructor called.";
35: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
36: }
37:
38: virtual void display()
39: {
40: cout << "\nThe amphibian has traveled "
41: << km << " kilometers on land and "
42: << milesAtSea << " sea miles.";
43: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
44: }
45: };
46: }