Re: Question about this piece of code.
On Aug 10, 11:18 am, Jianwei Sun <jsunnewsgr...@gmail.com> wrote:
I am reading a peice of code which is at the following link:
http://www.brpreiss.com/books/opus4/html/page141.html#SECTION007123000
000000000000
The code is like this:
Object& StackAsLinkedList::Pop()
{
if(count==0)
throw domain_error("stack is empty");
Object& const result=*list.First();
list.Extract(&result);
--count;
return result;
}
Does this code return a reference to local variable result? If this is
the case, then this code has problem?
Thanks,
J.W.
The list extract function is here:
http://www.brpreiss.com/books/opus4/html/page98.html#SECTION005210000...-=
Hide quoted text -
- Show quoted text -
If we ignore that result is a const and the return type is non-const,
it would seem that the returned value (a reference) refers to an
object that has been deleted inside the Extract function. This, of
course, is wrong.