Thread: stack

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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.

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, 08:13 AM
  5. stack
    By SilasP in forum C++ Programming
    Replies: 2
    Last Post: 02-18-2002, 09:42 AM