A string problem.
I'm making a text adventure engine. I want to use strings in the class and I think I'm leaving a lib out or something. Here's the code:
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
|
#include <iostream>
#include <string>
using namespace std;
int position[] = {0,1,2};
class roomcreation{
public:
void setName(string name);
string getName(string name);
void setDesc(string desc);
string getDesc(string desc);
private:
string itsName;
string itsDesc;
};
void roomcreation::setName(string name){
itsName = name;
}
void roomcreation::setDesc(string desc){
itsDesc = desc;
}
string roomcreation::getName(){
return string itsName;
}
string roomcreation::getDesc(){
return itsDesc;
}
|
you shouldn't have parameters in the getter functions ( and they should be declared const )
The ones in public?
Nevermind, I see what you're saying.
Yes.
You are declaring that this function exists and accepts a single string as the parameter:
string getDesc(string desc);
but defining this function, which takes no parameters.
1 2 3
|
string roomcreation::getDesc(){
return itsDesc;
}
|
The declaration must match the definition.
OH WOW
Thank you... That made so much sense! Lol.
Topic archived. No new replies allowed.