Text Adventure Problems

So I've been having problems with the use of strings in my class.


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
#include <iostream>
#include <string>
using namespace std;

int position[] = {0,1,2};

class roomcreation{
  public:

    void setName(string name);
    string getName();

  private:
    string itsName;
};

void roomcreation::setName(string name){
  name = itsName;
}

string roomcreation::getName(){
  return itsName;
}

int main(){

roomcreation room1;
room1.setName("Room 1");

string player;
string choice;

cout << "Please enter a name: ";
cin >> player;
cout << "Name has been set to " << player << ".\n\n";

cout << "You are in: " << room1.getName();

while(choice != "quit"){
  cin >> choice;}

return 0;}


I want room1.getName(); to return the name of the room but instead it doesn't return anything. Lol. Any help?
On setName you are copying the value of itsName ( the class member ) to name ( the function parameter )
Last edited on
Damn. Just had to switch the two around. Thanks a lot! ;]
Topic archived. No new replies allowed.