Re: stack display
From: James Dennett (jdennett_at_acm.org)
Date: 04/01/04
- Next message: Gary Schenk: "Re: [C] King exercise 6.1"
- Previous message: James Dennett: "Re: [C++] Initialization lists with array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Mar 2004 20:55:59 -0800
B. v Ingen Schenau wrote:
> stef wrote:
>
>
>>I want to display a stack but keep the elements in the stack as they were.
>>Does anyone know an easy way to do this? I am using the standard library
>>stack.
>
>
> There is not an easy way, as in a member function that gives you (read-only)
> access to the contained elements.
> However, std::stack is not a container in itself, but merely a wrapper
> around one of the other standard containers (by default around
> std::deque<>).
> One of the requirements that the standard imposes is that std::stack
> contains a protected member 'Container c', where Container is the type of
> container that std::stack uses internally.
>
> If you create a class that inherits from std::stack, you can then provide
> access to the underlying container object.
> It should be noted that std::stack does not have a virtual destructor, so it
> would be a bad idea to have a pointer (or reference) of type std::stack
> that actually refers to and object of your derived type, and through which
> you destroy the stack object.
>
> Bart v Ingen Schenau
Another alternative is to copy the stack, and then to
destroy the copy, leaving the original untouched.
-- James.
- Next message: Gary Schenk: "Re: [C] King exercise 6.1"
- Previous message: James Dennett: "Re: [C++] Initialization lists with array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|