home *** CD-ROM | disk | FTP | other *** search
- // ex07004.cpp
- // A class with two constructors
- #include <iostream.h>
-
- // ------------ a Cube class
- class Cube {
- int height, width, depth; // private data members
- public:
- // ------ constructor functions
- Cube() { /* does nothing */ }
- Cube(int ht, int wd, int dp)
- { height = ht; width = wd; depth = dp; }
- // ----- member function
- int volume() { return height * width * depth; }
- };
-
- main()
- {
- Cube thiscube(7, 8, 9); // declare a Cube
- Cube othercube; // a Cube with no initializers
- othercube = thiscube;
- cout << othercube.volume();
- }