Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class Unit {
  6. private:
  7.     int HP, SP;
  8. public:
  9.     void show () {
  10.         cout << "HP = "<< HP <<  ", SP = " << SP << endl;
  11.     }
  12.  
  13.     Unit ():HP(10), SP(1) {};
  14.  
  15.     Unit (int _hp, int _sp) : HP(_hp), SP(_sp) {}
  16.  
  17.     ~Unit () {
  18.         cout << endl << "Base object deleted" << endl;
  19.     }
  20.     /*
  21.     Unit operator= (const Marine& _unit) {
  22.         HP = _unit.HP;
  23.         SP = _unit.SP;
  24.     }
  25.     */
  26. };
  27.  
  28.  
  29. class Marine : public Unit {
  30. private:
  31.     int AT;
  32. public:
  33.     Marine () : Unit(20, 1), AT(2) {}
  34.  
  35.     Marine (int _hp, int _sp, int _at) : Unit(_hp, _sp), AT(_at) {}
  36.  
  37.     void show () {
  38.         Unit::show();
  39.         cout << "AT = " << AT;
  40.     }
  41.  
  42.     ~Marine () {
  43.         cout << endl << "Marine object deleted" << endl;
  44.     }
  45.  
  46.     Marine operator= (const Marine& _marine) {
  47.         Unit::operator=(_marine);
  48.         AT = _marine.AT;
  49.         return *this;
  50.     }
  51. };
  52.  
  53. int main() {
  54.     {
  55.    
  56.     Marine* pMarine;
  57.     Marine Tom(1, 1, 1);
  58.     Marine Ben, John;
  59.  
  60.     Unit _unit;
  61.     //Ben = Tom;
  62.  
  63.  
  64.  
  65.     pMarine = &Ben;
  66.  
  67.     pMarine -> show();
  68.  
  69.     _unit.show();
  70.  
  71.     cout << endl;
  72.     Ben.show();
  73.     }
  74.    
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement