Thread: lame class problem

  1. #1
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    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;
    
    }

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    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.
    Last edited by Polymorphic OOP; 02-07-2003 at 09:16 PM.

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    o so duh to me....thnx man, i felt ashamed for having to even post lol.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. template class default constructor problem
    By kocika73 in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2006, 09:42 PM
  2. problem with class
    By Mr.Pink in forum C++ Programming
    Replies: 26
    Last Post: 07-10-2005, 10:24 PM
  3. class, set, < problem
    By hk_mp5kpdw in forum C++ Programming
    Replies: 2
    Last Post: 07-10-2003, 09:25 AM
  4. static class problem.
    By Sebastiani in forum C++ Programming
    Replies: 3
    Last Post: 10-16-2002, 03:27 PM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM