Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Character
- {
- Character();
- void PrintHealth();
- string Name;
- float Health;
- };
- int main()
- {
- // Create PtrToChar with default constructor
- // Created at run-time and placed on the heap,
- // as opposed to compile-time when placed on stack.
- for (int i = 0; i < 10; i++)
- {
- Character* PtrToChar = new Character();
- cout << PtrToChar->Name << endl;
- PtrToChar->PrintHealth();
- delete PtrToChar;
- }
- system("pause");
- }
- Character::Character()
- {
- Name = "Default Name";
- Health = 100.f;
- }
- void Character::PrintHealth()
- {
- cout << "Health = " << Health << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment