-
lame class problem
Ok i'm throwing together a quick demonstration of using string w/ classes for a friend, and i know i'm missing something.
The parameter isn't modifying the variable in main. I'm missing soemthing simple, i'm tired so cut me a little slack :P
Code:
/* Steven Billington
Febuary 7, 2003
*/
#include <iostream>
#include <string>
using namespace std;
class get_input
{
public: get_input() {}
void get_name(string name);
};
int main(int argc, char* argv[])
{
get_input giobject;
string user_name; //not changing
giobject.get_name(user_name); //probs here
cout << user_name << endl;
return 0;
}
void get_input::get_name(string name)
{
cout << "Enter your name: ";
cin >> name;
}
-
get_name(string& name)
Also, you're not really using the concept classes and objects properly in that example. Right now, you're just using the class and a function container, which doesn't really make much sense. You most-likely want to encapsulate a string in that class and rather than making the membr function take an explicit parameter, using the string data member instead.
-
o so duh to me....thnx man, i felt ashamed for having to even post lol.