GregLeck

Untitled

Feb 17th, 2022
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5.  
  6. class Character
  7. {
  8. public:
  9.     Character();
  10.     ~Character();
  11.  
  12.     int* CharacterAge;
  13.     float* CharacterHealth;
  14. };
  15.  
  16.  
  17. int main()
  18. {
  19.     Character* Char = new Character;
  20.     delete Char;
  21.  
  22.     system("pause");
  23. }
  24.  
  25. Character::Character()
  26. {
  27.     cout << "A new character was created" << endl;
  28.     // Dynamically create an int and float on the heap
  29.     CharacterAge = new int(1);
  30.     CharacterHealth = new float(100.f);
  31. }
  32.  
  33. Character::~Character()
  34. {
  35.     cout << "Character destroyed" << endl;
  36.  
  37.     delete CharacterAge;
  38.     delete CharacterHealth;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment