Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Unit {
- private:
- int HP, SP;
- public:
- void show () {
- cout << "HP = "<< HP << ", SP = " << SP << endl;
- }
- Unit ():HP(10), SP(1) {};
- Unit (int _hp, int _sp) : HP(_hp), SP(_sp) {}
- ~Unit () {
- cout << endl << "Base object deleted" << endl;
- }
- /*
- Unit operator= (const Marine& _unit) {
- HP = _unit.HP;
- SP = _unit.SP;
- }
- */
- };
- class Marine : public Unit {
- private:
- int AT;
- public:
- Marine () : Unit(20, 1), AT(2) {}
- Marine (int _hp, int _sp, int _at) : Unit(_hp, _sp), AT(_at) {}
- void show () {
- Unit::show();
- cout << "AT = " << AT;
- }
- ~Marine () {
- cout << endl << "Marine object deleted" << endl;
- }
- Marine operator= (const Marine& _marine) {
- Unit::operator=(_marine);
- AT = _marine.AT;
- return *this;
- }
- };
- int main() {
- {
- Marine* pMarine;
- Marine Tom(1, 1, 1);
- Marine Ben, John;
- Unit _unit;
- //Ben = Tom;
- pMarine = &Ben;
- pMarine -> show();
- _unit.show();
- cout << endl;
- Ben.show();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement