Subj : Re: STL stack.pop() question To : borland.public.cpp.borlandcpp From : maeder Date : Tue Jun 29 2004 07:39 pm KonZa writes: > sorry if this is not the appropiate place to post this..but its short > anyway.. If you are using Bolrland C++, then you are right here. But please have a look at http://info.borland.com/newsgroups/ and read the newsgroup descriptions and guidelines before your next post, even if it's a short one again. This will help you find the appropriate newsgroup. > stack my_stack; > > my_stack.push(employee("john1")); > my_stack.push(employee("john2")); > > employee i = my_stack.top(); > my_stack.pop(); > my_stack.pop(); > > My question is how 'i' is assigned to the top of the stack since the > 'top' method return a reference. what is the mechanism here? copy > constructor? i is never assigned in this snippet. It's just initialized on the line of its definition; it will be destructed once it goes out of scope. The initialization of i takes a reference to employee as its argument. This means that the employee copy constructor will be used to initialize i. .