string function in implementation seciton
Jul 20, 2013 at 4:28pm UTC
Hello, I am having trouble with the implementation section of my code. The trouble I am having is with the """"string Name::RevereUsingString()""" function/method. I keep getting an error saying that """"control reaches end of non-void function"""". The two void function below the ""string Name::RevereUsingString()"" fuction/method are ok and ready to be worked on.
Can anybody show me how to implement the ""string Name::RevereUsingString()"" correctly in the implementation section?
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
#include <iostream>
#include <string>
using namespace std;
//-------------Class Section------------------------------------
class Name
{
public :
string Names[5];
public :
string TheName;
Name()
{ TheName="" ; }
Name(string name)
{ TheName=name; }
string ReverseUsingString();
void ReverseUsingArray(char Reversed[]);
void ReverseUsingPtrs(char *Reversed);
void operator =(char *name) {TheName=name;}
};
//--------------------------------------------------------------------------------
//--------------------Implementation Section--------------------------------------
//--------------------------------------------------------------------------------
string Name::ReverseUsingString() //error here
{ //error here
} //error here
void Name::ReverseUsingArray(char Reversed[])
{
}
void Name::ReverseUsingPtrs(char *Reversed)
{
}
//------------------------------------------------------------------------------
//----------------------------Main Function-------------------------------------
int main()
{
Name Names[5];
Names[0] = "Ben Dover" ;
Names[1] = "Chuck Roast" ;
Names[2] = "Jim Naysium" ;
Names[3] = "Ella Quint" ;
Names[4] = "Justin Case" ;
char reversedname1[100], reversedname2[100];
for (int i=0; i<5; ++i)
{
Names[i].ReverseUsingArray(reversedname1);
Names[i].ReverseUsingPtrs(reversedname2);
cout << "Original Name : " << Names[i].TheName << endl;
cout << " reversed with arrays: -->" << reversedname1 << "<--\n" ;
cout << " reversed with ptrs : -->" << reversedname2 << "<--\n" ;
cout << " reversed with string: -->" << Names[i].ReverseUsingString() << "<--\n\n" ;
}
system("pause" ); return 0;
}
Jul 20, 2013 at 4:37pm UTC
If you say that you are going to return something, then return something.
Simple, ¿right?
1 2 3 4
string Name::ReverseUsingString()
{
return "foo" ;
}
Jul 20, 2013 at 4:58pm UTC
haha, Thanks.. Thats awesome, It worked..
Topic archived. No new replies allowed.