Reputation:
I'm trying to push
to a queue
inside of a function called in multiple places.
From my limited experience, if I pass the queue
as is, I think it will be a copy, so only the copy will be push
ed.
How can the original queue
be passed as a function parameter and push
ed inside the function?
Upvotes: 0
Views: 1373
Reputation: 112
Pass it by reference. Something like void myFunc(queue& q). This will pass the address of the queue so it is efficient. It is better than passing a pointer to the queue because myFunc() does not have to worry about it being a null pointer.
Upvotes: 1