I have a question about passing reference
I have a function prototype like void Queue::enqueue(Const Obj& o);
The first case, I try to pass a temp Obj instance to a function
but compile error occurs
I got compile error like followingCode:Queue q; q.enqueue(Obj(10));
g++ -g -Wall -c main.cpp -o main.o
main.cpp: In function ‘int main()’:
main.cpp:17: error: no matching function for call to ‘Queue::enqueue(Obj)’
queue.h:29: note: candidates are: void Queue::enqueue(Obj&)
Then I try to modify the code as following
And this one can be compiledCode:Queue q; Obj o(10); q.enqueue(o);
Could anyone explain what's the difference between these two?
Thx in advance