Using custom classes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • s0lidjacks0n
    New Member
    • Feb 2010
    • 2

    Using custom classes

    I'm using the code below and I keep getting issues with using strings and the custom class Menu. Any help would be greatly appreciated.

    Code:
    /*Andrew Smith
     *ajs0025
     *Menu.cpp
     */
    #include <iostream>
    #include <vector>
    #include <string>
    
    
    using namespace std;
    
    //modified from your example menu class.
    class Menu
    {
    public:
    void printOptions( vector<string> options )
    {
    	for(int i=0;i < options.size(); i++)
    	{
    	string option = options.at(i);
    	cout<< option << endl;
    	}	
    }
    
    void addOption( string newOption, vector<string> options){
    	int j = options.size();
    	j++;
    	options.push_back (newOption);
    }
    
    //modified from your example "http://www.eng.auburn.edu/~xqin/courses/comp2710/getnumber.cpp"
    int getNumber ( int& choice )
    {
      while ( !( cin >> choice ) ) {
        if ( cin.eof() )
          return 0;
        else {
          char ch;
          cin.clear();
          cout<<"Invalid input, please try again: ";
          while (cin.get(ch) && ch != '\n' );
        }
      }
    
      return choice;
    }
    	
    private:
    vector<string> options;
    
    
    };
    
    
    
    class main
    
    {
    
    	Menu test;
    
    	string testString; 
    	testString = "this is a test";
    
    	test.addOption(testString);
    
    	test.printOptions();
    
    	
    
    };
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    What issues? Please describe your problem properly and fully.

    Comment

    • s0lidjacks0n
      New Member
      • Feb 2010
      • 2

      #3
      Sorry, I figured it out.
      it had to do with the fact that I had declared main a class rather than a function, because I'm a moron.

      Comment

      Working...