How to Pass Class as a Function Arguement?

At the bottom of my code is my function definition. It says player1 is undeclared. How do I get my function to output the class I made, "PlayerClass"?

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <cstdlib>
#include <iostream>
#include <string>

// Objects:
// Sword traits, sword class, a class within a class
// Save created profile onto file
// Create save points onto file
// add a story

using namespace std;

string name;
int lvl;

// inventory
string sword;
string shield;
string handle;

// player naviagating
string path1;
int you;

// Items
string masterSword;
string WoodenShield;

// misc
int exp;
string pauseInput;

class PlayerClass{
      
      public:
             // Player's name
             void setName(string x){
                  name = x;
                  }
              string getName(){
                     return name;
                  }
              // Player's Level
             void setLevel(int x){
                  lvl = x;
                  }     
              int getLevel(){
                  return lvl;
                  }
              // Experience Points
              void setExp(int x){
                   exp = x;
                   }
              int getExp(){
                  return exp;
                     }
              // Player's Inventory
              void setSword (string x, string y){
                   sword = x;
                   handle = y;
                   }
              string getSword(){
                     return sword;
                     }
              string getHandle(){
                     return handle;
                     }
              string getShield(){
                     return shield;
                   }
      private:
              string name;
              int lvl;
              string sword;
              string handle;
              string shield;
              int exp;
              };
// Map
string map[50][50];
//map[25][25] = {{"The"},{"Post"}};
        
void pause(PlayerClass);

int main()
{
    
    //pause
    // string q = pause( PlayerClass);
    
    cout << "What is your name? \n";
    cin >> name;
    
    // Send information to PlayerClass (Profile)
    PlayerClass player1;
    player1.setName(name);
    player1.setLevel(1);

    // Output person1's player information
    cout << "\n";
    cout << "Profile: \n";
    cout << "Name: " << player1.getName();
    cout << "\n";
    cout << "Level: " << player1.getLevel();
    cout << "\n";
    cout << "Inventory: " << player1.getSword() << ", " << player1.getShield();
    cout << "\n";

    // Game Starts ...
    
    // Inform player of surroundings
    
    // Location 25 (cutscene)
    cout << "You are at The Post" << endl;
    //you = map[50][50];
    
    // Choose Path
    cout << "Where to go? (up, left)" << endl;
    cin >> path1;
    cout << "\n";   
    // Player Chose left (Cave)
    if (path1 == "left"){
       cout << "You opened the chest and found a sword";
       player1.setSword("Katana", "red handle");
       player1.setExp(+3);
       }
       // Player went up (Field)
       else if (path1 == "up"){
                  cout <<"Welcome to Field" << endl;
                  } 


    // Output person1's player information
    cout << "\n";
    cout << "Profile: \n";
    cout << "Name: " << player1.getName();
    cout << "\n";
    cout << "Level: " << player1.getLevel();
    cout << "\n";
    cout << "Inventory: " << player1.getSword() << " with " << player1.getHandle();
    cout << "\n";
    
    system("PAUSE");
    return 0;
}

// pause function definition
void pause(PlayerClass){
        cout << "Game is paused";
        cin >> pauseInput;
        // option list
        cout << "Stats" << endl;
        cout << "Return to Game" << endl;
        cout << "Quit Game" << endl;
        // Actions
        if (pauseInput == "Stats"){
                       
    // Output person1's player information
    cout << "\n";
    cout << "Profile: \n";
    cout << "Name: " << player1.getName();
    cout << "\n";
    cout << "Level: " << player1.getLevel();
    cout << "\n";
    cout << "Inventory: " << player1.getSword() << ", " << person1.getShield();
    cout << "\n";                     
        };

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

void pause(PlayerClass obj){
	cout << "Game is paused";
	cin >> pauseInput;
	// option list
	cout << "Stats" << endl;
	cout << "Return to Game" << endl;
	cout << "Quit Game" << endl;
	// Actions
	if (pauseInput == "Stats"){

		// Output person1's player information
		cout << "\n";
		cout << "Profile: \n";
		cout << "Name: " << obj.getName();
		cout << "\n";
		cout << "Level: " << obj.getLevel();
		cout << "\n";
		cout << "Inventory: " << obj.getSword() << ", " << obj.getShield();
		cout << "\n";
	}
}


then call the pause function like this:

pause(player1);
A simple solution and worked perfectly. Thanks.
Your welcome :)
Topic archived. No new replies allowed.