Re: stack display

From: James Dennett (jdennett_at_acm.org)
Date: 04/01/04


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.



Relevant Pages

  • Re: STL stack/deque
    ... >> What is the basic operation on a stack? ... >> may require expansion of the container. ... the default container that stack is using. ... As for the 500-gallon gas tank analogy: To me that's like using a ...
    (alt.comp.lang.learn.c-cpp)
  • Re: OO Design induces an existential crisis
    ... First, Andy, I do not have a fixation on containers. ... We have many categories of classes in object technology. ... One of those categories is the container class. ... We can create instances of class Stack. ...
    (comp.object)
  • Re: Lets put this to rest
    ... The above is consistent with a stack; ... it leaves out the FIFO nature of a stack. ... It's a container with order applied. ... the actual policy can be left to design when that particular business ...
    (comp.object)
  • Re: display stack
    ... >> Container. ... Perhaps you could derive your own stack class from ... > now when I read your posting I looked it up in the Holy Standard, ... > struct Hack: public Stack ...
    (comp.lang.cpp)
  • Re: Whats the secmantics of IoDetachDevice?
    ... C's driver will have its FastIoDetachDevice callback called, ... and should detach and destroy C in this callback. ... then A is sure to be removed from the stack. ...
    (microsoft.public.development.device.drivers)