문제

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