stack

This is a discussion on stack within the C++ Programming forums, part of the General Programming Boards category; Can you declare a stack globally? Code: stack< int > stk;...

  1. #1
    Registered User CASHOUT's Avatar
    Join Date
    Jul 2011
    Location
    Florida
    Posts
    88

    stack

    Can you declare a stack globally?
    Code:
    stack< int > stk;
    Last edited by CASHOUT; 07-14-2013 at 08:10 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    Sure.

    Try it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,611
    Let me ask you: why do you think you can (or can not)?
    Why the question, and why haven't you tried (or have you?)?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User CASHOUT's Avatar
    Join Date
    Jul 2011
    Location
    Florida
    Posts
    88
    Quote Originally Posted by Elysia View Post
    Let me ask you: why do you think you can (or can not)?
    Why the question, and why haven't you tried (or have you?)?
    Sorry that was a horrible question.
    I wanted to know if there was a way to pass a stack as a parameter to a function rather than having to declare it globally.

    I had tried it already and the program ran fine before I asked.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    Sure, you read your book and you learn all about reference parameters.

    Eg.
    Code:
    void foo ( stack<int> &mystack ) {
      mystack.push(42);
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stack
    By Tool in forum C++ Programming
    Replies: 4
    Last Post: 06-14-2010, 02:18 AM
  2. What's a stack?
    By advancedk in forum C Programming
    Replies: 5
    Last Post: 09-23-2008, 03:06 AM
  3. Stack
    By praul in forum C++ Programming
    Replies: 4
    Last Post: 04-20-2006, 10:25 AM
  4. help with stack
    By razoblade in forum C Programming
    Replies: 1
    Last Post: 02-25-2002, 07:13 AM
  5. stack
    By SilasP in forum C++ Programming
    Replies: 2
    Last Post: 02-18-2002, 08:42 AM

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