Question

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 pushed.

How can the original queue be passed as a function parameter and pushed inside the function?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top