Thread: OOP and global arrays

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

  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, 05: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-04-2003, 12:21 AM
  4. Avoiding Global Variables in games, how?
    By Unregistered in forum Game Programming
    Replies: 5
    Last Post: 03-24-2002, 07:33 AM