Using stack of stl with custom container.

This is a discussion on Using stack of stl with custom container. within the C++ Programming forums, part of the General Programming Boards category; Hey everyone! I have written my own kind-of-custom-version of the stack container in the STL. The iterators seem to be ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    69

    Using stack of stl with custom container.

    Hey everyone!

    I have written my own kind-of-custom-version of the stack container in the STL. The iterators seem to be working and the basic push/pop/size I did.

    Now there is one thing that doesnt seem to work, and I have no idea how to start:

    Code:
    std::stack<int> s(mstack);
    It declares the real version of the stack, with my version of the stack as a parameter. The error I get is:

    Code:
    main.cpp:34: error: no matching function for call to `std::stack<int, std::deque<int, std::allocator<int> > >::stack(MutantStack<int>&)'
    /usr/include/c++/3.4/bits/stl_stack.h:111: note: candidates are: std::stack<int, std::deque<int, std::allocator<int> > >::stack(const std::stack<int, std::deque<int, std::allocator<int> > >&)
    /usr/include/c++/3.4/bits/stl_stack.h:144: note:                 std::stack<_Tp, _Sequence>::stack(const _Sequence&) [with _Tp = int, _Sequence = std::deque<int, std::allocator<int> >]
    Im not sure where to start to make it work with the real stack.
    Thank you for any tips!

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    You could create an
    Code:
    operator std::stack<Type> () { /* ... */ }
    type-conversion function. Or you could make your class inherit from std::stack, I suppose (though that's probably not what you want to do).

    [edit] Some useful-looking links:

    [/edit]
    Last edited by dwks; 09-15-2009 at 11:38 AM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-12-2006, 12:41 AM
  2. Custom container should expand STL containers?
    By LinuxCoder in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2006, 03:05 PM
  3. Linked List Queue Implementation help
    By Kenogu Labz in forum C++ Programming
    Replies: 8
    Last Post: 09-21-2005, 11:14 AM
  4. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 10:12 PM
  5. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 06:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21