Function problem

Ok, so i have 3 functions, all of them strings.
I 'call to' the first two successfully, inputing and returning strings, but the third i use the exact same method and it says "cannot convert std::string' to std::string()(std::string)' in assignment". Any ideas of what i may be doing wrong? Or if it helps, heres the majority of the program (replaced long talking parts with blahblah):

#include <iostream>
#include <cstring>
#include <string>
using namespace std;

string begining1 (){
string name;
cout << "blahblah";
cin >> name;
cout << "Right, so your name is " << name << " blahblah.";
return name;
}

string begining2 (string rival_gender){
string name, rg1, rg2;
if (rival_gender == " he "){
rg1= " him ";
rg2= " his ";
}
else {
rg1= " her ";
rg2= " her ";
}
cout << " blahblah" <<rg1<< "?! What was"<<rg2<<"name again? ";
cin >> name;
return name;
}

string pokemon (string r_n){
cout << "testing1/2/3"; //this is the function that wont work
}


int main (){
cout << "Before we get started, how about some info: Gender? (male/female): ";
string main_name, rival_name, gender1="n/a",gender,rival_gender;
while (gender1=="n/a"){
cin >> gender;
if (gender=="male"){
gender1=" Mr. ";
rival_gender=" She ";
}
if (gender=="female"){
gender1=" Ms. ";
rival_gender=" He ";
}
if (gender1 == "n/a"){
cout << "Um, try that again. male or female: ";
}
}
main_name = begining1 ();
cout << "\nWelcome " << main_name;
rival_name = begining2 (rival_gender);
pokemon = pokemon (rival_name); //call to function that doesn't work
system("PAUSE");
}
Won't load tracking options. Just making sure i can still see replies.
Try placing a cout after the rival_name and before pokemon in the main function to see if rival name is being returned correctly. Also why aren't you returning anything in the third function.
The rival_name is returning perfectly. Any other ideas?

And i havent finished the third function yet. Its going to be rather complicated, so i figured it'd be a good idea to take it one bit at a time.
Last edited on
It's returning perfectly. Any other ideas?


It's not returning perfectly. It's broken, but not in such a way that the code won't compile. The function pokemon claims to return a string, so you should make sure it does. Something like:

1
2
3
4
5
string pokemon (string r_n){
cout << "testing";
std::string someString("A string");
return someString;
}



Last edited on
pokemon has the same name as your function, and it screws up the compiler. Try changing the name of the function to Pokemon(string r_n), instead. ( Capital 'P' in the beginning.. )
Last edited on
That worked! All it needed was to be capitalized! Thanks whitenite1!
Glad I could help, Nathan.
Topic archived. No new replies allowed.