Advertisement
Guest User

Oleg Orlov / Pure virtual functions

a guest
Feb 10th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. enum Codes
  6. {
  7.     Oct = 8,
  8.     Dec = 0xa,
  9.     Hex = 0x10,
  10. };
  11.  
  12. class Base
  13. {
  14. protected:
  15.     int value;
  16.  
  17. public:
  18.     void SetValue(int n)
  19.     {
  20.         this->value = n;
  21.         Print();
  22.     }
  23.  
  24.     virtual void Print(void) = 0;
  25. };
  26.  
  27. class Hex : public Base
  28. {
  29. public:
  30.     void Print(void)
  31.     {
  32.         cout << hex << this->Base::value << endl;
  33.     }
  34. };
  35.  
  36. class Oct : public Base
  37. {
  38. public:
  39.     void Print(void)
  40.     {
  41.         cout << oct << this->Base::value << endl;
  42.     }
  43. };
  44.  
  45. class Dec : public Base
  46. {
  47. public:
  48.     void Print(void)
  49.     {
  50.         cout << dec << this->Base::value << endl;
  51.     }
  52. };
  53.  
  54. class Numeral : Dec, Oct, Hex
  55. {
  56. public:
  57.     void Call(int num_sys, int value)
  58.     {
  59.         switch(num_sys)
  60.         {
  61.             case Codes::Oct:
  62.                 this->Oct::SetValue(value);
  63.                 break;
  64.             case Codes::Dec:
  65.                 this->Dec::SetValue(value);
  66.                 break;
  67.             case Codes::Hex:
  68.                 this->Hex::SetValue(value);
  69.                 break;
  70.         };
  71.     }
  72. };
  73.  
  74. void main(void)
  75. {
  76.     Numeral *object = new Numeral();
  77.    
  78.     object->Call(Codes::Oct, 9);
  79.     object->Call(Codes::Dec, 0xa);
  80.     object->Call(Codes::Hex, 0xf);
  81.    
  82.     delete object;
  83.  
  84.     system("pause");
  85. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement