How to pass variable(queue) in function by reference C++

Hi, I'm trying to simulate a movie theater program where customers enter the theater, wait on line, and enter the theater based on what movie they're seeing and if they're able to fit. To serve my guests, i need to move them from the line they are on to the movie of their choice. Like I said, every time a new party is being "served" there's a lot of logic checking for which theater and if there's enough room to seat the party, so without hardcoding thousands of lines i would like to use a function. I have functions to display the occupancy of the theaters, but unlike the display function i need to make actual changes to the variables it's calling.

I believe I have to pass each object in by reference, but I'm just wondering what is the syntax

This is how I would imagine it would be like:

1
2
3
4
5
6
7
void ServeLine (queue<queue<myObject>>, queue<myObject>, int, int)//proto

ServeLine(Theater1, Line1, EmptyCount1, Ticket1)//call

void ServeLine(queue<queue<myObject>> &T1, queue<myObject> &L1, int &E1, int &T1)//def
{
}


and any changes I make to the "temporary" variable T1 would be made to the global variable Theater1, etc.

Is this correct?
Last edited on
1
2
3
4
5
6
7
8
void ServeLine (queue<queue<myObject>>&, queue<myObject>&, int&, int& ) ; //proto

erveLine(Theater1, Line1, EmptyCount1, Ticket1) ; //call

void ServeLine(queue<queue<myObject>> &T1, queue<myObject> &L1, int &E1, int &T1)//def
{
    // ...
}
I tried implementing it, and it works great.

Thanks :)
Topic archived. No new replies allowed.