-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeclare_classes_and_objects.cpp
More file actions
43 lines (33 loc) · 1010 Bytes
/
declare_classes_and_objects.cpp
File metadata and controls
43 lines (33 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Declare Classes and Objects
#include <iostream>
#include <vector>
#include <string> // remember standard strings are initialized to empty string
/*Create a class*/
class Player {
// attributes
std::string name{ "New Player" };
int health{ 100 };
int xp{ 0 };
// methods (functions)
void talk(std::string);
bool is_dead();
};
class Accout {
// attributes
std::string name{ "Account" };
double balance{ 0 };
// methods
bool deposit(double); // return True or False depending on whether the account action was successful
bool withdraw(double);
};
int main() {
// Instantiate 2 objects using Player class
Player devere;
Player stella;
//Player players[]{ devere, stella };
std::vector<Player> player_vec{ devere, stella };
// Create objects on the heap. Pointer to Player object on the heap
Player* tuitty = new Player; // type of pointer, name of pointer = newly allocated memory in the heap
Accout devere_account;
return 0;
}