Thread: Need help with creating arrays outiside functions

  1. #1
    Registered User
    Join Date
    Oct 2009

    Need help with creating arrays outiside functions

    okay so straight out, i need my arrays and their size integer variable to be global functions, but my compiler isn't accepting it. i use dev c++. so what do i do?

    using namespace std;
    int size;
    char Field[size][size];
    char Ground[size][size];
    void Diff()
         char ch;
        cout<<"Please select a level of Difficulty:"<<endl;
        if(ch=='E') size=9;
        if(ch=='M') size=17;
        if(ch=='D') size=25;
    that's the code

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    The size must be a compile time constant.

    You probably do not need to use global variables. I suggest that you use a std::vector that is passed by (const) reference as needed.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a new record
    By Aisthesis in forum C++ Programming
    Replies: 3
    Last Post: 05-28-2009, 03:56 PM
  2. Arrays and Functions
    By KunoNoOni in forum Game Programming
    Replies: 12
    Last Post: 10-04-2005, 09:41 PM
  3. functions and arrays
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 03-14-2002, 09:57 AM
  4. 2D arrays with functions made easy
    By goran in forum C Programming
    Replies: 1
    Last Post: 09-17-2001, 12:08 PM
  5. elements of arrays; functions
    By sballew in forum C Programming
    Replies: 6
    Last Post: 09-03-2001, 01:48 AM