1

Hello the aim of this program is to initialize all elements of the vector Rooms to the string Empty, this is my first attempt at tackling vectors and passing by reference as such I'm not sure what is wrong.

 #include <iostream>
 #include <string>
 #include <vector>

 using namespace std;

 void mainMenu(vector <int> &VectorRooms(), string &EmptyString);

 int main()
{
  vector < int > Rooms(13);
  string str1 = "Empty";

   mainMenu(Rooms, str1);
}

   void mainMenu(vector <int> &VectorRooms(), string &EmptyStrings)
  {
   int i;
   for (i = 0; i < VectorRooms.size(); i++)
    {
    VectorRooms[i] = EmptyStrings;
    cout << VectorRooms[i] << endl;
    }
  } 

1 Answer 1

1

You have:

void mainMenu(vector <int> &VectorRooms(), string &EmptyStrings)

You mean:

void mainMenu(vector <int> &VectorRooms, string &EmptyStrings)

Remove those parentheses. With the parentheses there, you're actually declaring VectorRooms as a function pointer to a function that returns a vector <int> & and takes no parameters, and index [] is invalid on a function pointer type. That, of course, isn't your intention

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.