This problem is driving me nuts!(function call)

This is a discussion on This problem is driving me nuts!(function call) within the C++ Programming forums, part of the General Programming Boards category; Trying to pass some strings and integers into a menu class. menu.initialize should take a string, string, array of strings, ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    163

    This problem is driving me nuts!(function call)

    Trying to pass some strings and integers into a menu class.
    menu.initialize should take a string, string, array of strings, array of integers and an integer. That's exactly what I'm passing to it too!

    main:
    Code:
    string mainHead = "Main Menu";
        string mainPrompt = "Enter choice: ";
        int mainNumChoices = 7;
        int checkNumChoices = 3;
        int saveNumChoices = 4;
        int mainChoices[7] = {1,2,3,4,5,6,7};
    
        string mainBody[7]= {"Add Checking", "Add Savings", "Remove Checking",
                "Remove Savings", "View Checking", "View Savings", "Exit"};
        menu newMenu;
        newMenu.initialize(mainHead, mainPrompt, mainBody[7], mainChoices[7], mainNumChoices);
    menu:
    Code:
    //menu
    
    #ifndef    menu_h
    #define    menu_h
    
    #include <string>
    #include <iostream>
    
    const int MAX_NUM_ITEMS = 10;
    using namespace std;
    
    class menu
    {
          public:
                 menu();
                 menu(string, string, string[], int[], int);
                 ~menu();
                 void initialize(string, string, string[], int[], int);
                      //Title, prompt, body[MAX_NUM_ITEMS],
                      //current choice[MAX_NUM_ITEMS], numChoices)
                 void display();
                 int get_choice();
                 void run();
    
    
    
          private:
                  int choice, numChoices, choices[MAX_NUM_ITEMS];
                  string title, prompt, body[MAX_NUM_ITEMS];
    
                  bool validate_choice();
    
    };
    
    #endif
    
    
    //menu.cpp
    
    #include "menu.h"
    
    
    void menu::initialize(string _title, string _prompt, string _body[], 
                                      int _currentChoice[], int _numChoices)
    {
              title = _title;
              prompt = _prompt;
              numChoices = _numChoices;
              for(int i = 0; i < numChoices; i++)
              {
                      currentChoice[i] = _currentChoice[i];
                      body[i] = _body[i];
              }
    }//! End of constructor
    error:
    Code:
    20 C:\Documents and Settings\Owner\Desktop\CodeBlocks\Take Home Final\mainline.cpp no matching function for call to `menu::initialize(std::string&, std::string&, std::string&, int&, int&)' 
     note C:\Documents and Settings\Owner\Desktop\CodeBlocks\Take Home Final\menu.h:18 candidates are: void menu::initialize(std::string, std::string, std::string*, int*, int)
    I just don't get it. It's that damn & sign again. I swear that one symbol is kicking my ass lately. I did a pretty thourogh(sp?) search and couldn't find anything, plus having tried various things for about 2 hours now... Can anybody help a poor soul out?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    >> newMenu.initialize(mainHead, mainPrompt, mainBody[7], mainChoices[7], mainNumChoices);
    When you put mainBody[7], you are not passing an array, you are passing the element at index 7 in the array, which is just a string. Since mainBody and mainChoices are arrays, just use mainBody and mainChoices by themselves:
    Code:
    newMenu.initialize(mainHead, mainPrompt, mainBody, mainChoices, mainNumChoices);

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    That did it. I guess I should have asked on here sooner, and of course it was something simple. Daved you're a saviour!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 01:54 PM
  2. Problem while constructing IP packet and sending using socket() system call
    By cavestine in forum Networking/Device Communication
    Replies: 10
    Last Post: 10-15-2007, 05:49 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. No call to execv
    By protocol78 in forum C Programming
    Replies: 4
    Last Post: 05-08-2007, 11:43 AM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21