OOP and global arrays

This is a discussion on OOP and global arrays within the C++ Programming forums, part of the General Programming Boards category; here is a mock up of what i have: Code: struct blah { // some stuff }; blah array[100]; ... ...

  1. #1
    Registered User dan20n's Avatar
    Join Date
    Jan 2005
    Posts
    24

    OOP and global arrays

    here is a mock up of what i have:

    Code:
    struct blah {
    // some stuff
    };
    
    blah array[100];
    
    ...
    // functions..
    ...
    this is in a seperate file to the main, [edit] i think [/edit] the compiler asks me to place this decleration inside a function i need it to be global, any ideas? its late where i am so if u need more info or the actual code then ask. Cheers

    Code:
    28 C:\ass1.cpp variable-size type declared outside of any function
    hope this helps
    Last edited by dan20n; 02-24-2005 at 03:40 AM.
    Meg: Everybody! Guess what I am?
    Stewie: Hm, the end result of a drunken back-seat grope-fest and a broken prophylactic?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    Your example says 100, and your error message says "variable-size"
    So which is it?

    If you need it to be variable, then try
    Code:
    blah *array;
    
    // then inside some early function
    array = new blah[howmany];
    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
    Registered User dan20n's Avatar
    Join Date
    Jan 2005
    Posts
    24
    Yeah sorry should post the code

    Code:
    static int MAXRECORDS = 100;
    
    struct PetRecord {
    // stuff
    };
    
    
    PetRecord PetID[MAXRECORDS];
    Hope this helps

    more info: this is not inside any function, its in my file ass1.cpp which is before all my functions.
    Meg: Everybody! Guess what I am?
    Stewie: Hm, the end result of a drunken back-seat grope-fest and a broken prophylactic?

  4. #4
    Registered User dan20n's Avatar
    Join Date
    Jan 2005
    Posts
    24
    Forgot to make it a constant for anyone who cares.
    *so angry*
    Meg: Everybody! Guess what I am?
    Stewie: Hm, the end result of a drunken back-seat grope-fest and a broken prophylactic?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP question (global variable?)
    By VikingBow in forum C# Programming
    Replies: 5
    Last Post: 12-26-2007, 04:48 PM
  2. Global objects and exceptions
    By drrngrvy in forum C++ Programming
    Replies: 1
    Last Post: 09-29-2006, 07:37 AM
  3. OOP for DirectPlay Peer to Peer program
    By curlious in forum Networking/Device Communication
    Replies: 0
    Last Post: 11-03-2003, 11:21 PM
  4. Avoiding Global Variables in games, how?
    By Unregistered in forum Game Programming
    Replies: 5
    Last Post: 03-24-2002, 06:33 AM

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