質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top