Hey guys, so I'm trying to create a queue using a linked list I've written. But when I try to compile I get an error saying:
"queue.cpp: In member function ‘banfield_lab6::node::value_type& banfield_lab6::queue::front()’:
queue.cpp:18:25: error: invalid initialization of non-const reference of type ‘banfield_lab6::node::value_type& {aka int&}’ from an rvalue of type ‘banfield_lab6::node::value_type {aka int}’
return data.getCurrent();"
I was wondering whether anyone would be kind enough to explain what I'm doing wrong. Here's the implementation of front() from the queue.cpp:
'getCurrent' returns a value.
'front' returns a reference.
If you return getCurrent() from front(), you are returning a reference to a copy of a variable (sine getCurrent returns by value instead of by reference).
A possible solution is to have getCurrent (and possibly getData) return a reference rather than a value, but it's difficult to say whether or not that's a good idea without seeing the overall design.