ulvis.paste.net

Paste Search Dynamic
Recent pastes
objects
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Box{
  5. public:
  6.     static int objectCount;
  7.  
  8.     //Constructor definition
  9.     Box(double l = 2.0, double b = 2.0, double h = 2.0) {
  10.         cout << "Constructor Called." << endl;
  11.         length = l;
  12.         breadth = b;
  13.         height = h;
  14.  
  15.         //Increase everytime the object is created
  16.         objectCount++;
  17.     }
  18.     double Volume() {
  19.         return length * breadth* height;
  20.     }
  21. private:
  22.     double length;
  23.     double breadth;
  24.     double height;
  25. };
  26. // Initialize static member of class Box
  27. int Box::objectCount = 0;
  28.  
  29. int main(void) {
  30.     Box Box1(3.3, 1.2, 1.5);
  31.     Box Box2(8.5, 6.0, 2.0);
  32.  
  33.     cout << "Total objects: " << Box::objectCount << endl;
  34.  
  35.     return 0;
  36. }
Parsed in 0.006 seconds