I have looked around, and can't find anywhere that explicitly answers how to pass an array from function1, class1 to function2, class2.
This is my code.
Game Class
void Game::userInputNumbers()
{
for (int i = 0; i < 6; i++)
{
std::cin >> myNumbers[i];
}
for (int i = 0; i < 6; i++)
{
std::cout << myNumbers[i] << " ";
}
}
Main
game.userInputNumbers();
user.setTicket(int a, myNumbers[6], username);
User Class
void User::setTicket(int i, int myNumbers[6], std::string username)
{
std::ofstream fout (username + "Ticket" + a + ".txt");
for (int i = 0; i < 6; i++)
{
fout << myNumbers[i] << std::endl;
}
}
I'm aware that I will probably have to declare the array as static (not really sure how, or what the implications of that are) and that I will have to use pointers in some form.
Also please note, username and int a have been declared elsewhere in the program and work for other functions so I'm not worried about those, and I have left out all unnecessary code such as my includes as again the rest of the program compiles fine
Thanks in advance
user.setTicket(a, myNumbers, username);. Isn't it?std::vector.vectoris a dynamic array and guarantees O(1) indexing.