Advertisement
monstrasitix

Lear

Nov 29th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. #include <string>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. class Entity
  8. {
  9.     private:
  10.         const string word;
  11.         const bool boolean;
  12.         const signed int integer;
  13.         static signed int entityCount;
  14.     public:
  15.         Entity(void);
  16.         Entity(const signed int& integer, const string& word, const bool& boolean);
  17.    
  18.         static signed int getEntityCount(void);
  19.    
  20.         const string* const getWord(void) const;
  21.         const bool* const getBoolean(void) const;
  22.         const signed int* const getInteger(void) const;
  23.        
  24.         virtual void print(void) = 0; // const;
  25. };
  26.  
  27. class SpecificEntity : public Entity
  28. {
  29.     public:
  30.         SpecificEntity(void);
  31.         SpecificEntity(const signed int& integer, const string& word, const bool& boolean);
  32.         void print(void) const;
  33. };
  34.  
  35. int Entity::entityCount = 0;
  36. Entity::Entity(void) : Entity(0, "", false) {}
  37.  
  38. Entity::Entity(const signed int& integer, const string& word, const bool& boolean)
  39.     : integer(integer)
  40.     , word(word)
  41.     , boolean(boolean)
  42. {
  43.     this->print();
  44.     ++Entity::entityCount;
  45. }
  46.  
  47. const string* const Entity::getWord(void) const { return &this->word; }
  48. const bool* const Entity::getBoolean(void) const { return &this->boolean; }
  49. const signed int* const Entity::getInteger(void) const { return &this->integer; }
  50. signed int Entity::getEntityCount(void) { return Entity::entityCount; }
  51.  
  52. /*
  53. void Entity::print(void) const
  54. {
  55.     cout
  56.         << "Integer: " << this->integer << endl
  57.         << "Word: " << this->word << endl
  58.         << "Boolean: " << this->boolean << endl
  59.         << endl;
  60. }
  61. */
  62.  
  63. void SpecificEntity::print(void) const
  64. {
  65.     // this->print();
  66.     cout << "Modified";
  67. }
  68.  
  69. SpecificEntity::SpecificEntity(void) : Entity(0, "", false) {}
  70. SpecificEntity::SpecificEntity(const signed int& integer, const string& word, const bool& boolean) : Entity(integer, word, boolean){}
  71.  
  72.  
  73. int main ()
  74. {
  75.     const bool boolean {true};
  76.     const signed int integer {50};
  77.     const std::string word {"Some word"};
  78.    
  79.     const int entitiesLength {3};
  80.     std::vector<SpecificEntity> entities;
  81.    
  82.     for (int index = 0; index < entitiesLength; index++)
  83.         entities.push_back({ integer, word, boolean });
  84.    
  85.     std::cout << "Total number of entities: " << Entity::getEntityCount() << std::endl;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement