Results 1 to 5 of 5

Thread: Array of Integers as a class member

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Posts
    164

    Array of Integers as a class member

    I've tried all night to figure this out, and I know I'm just going in circles...

    I want to have an array of integers as a private variable of my class and I want to populate it with all zeros.

    When I assign and print out the contents in the constructor, everything looks fine, but when I print out the array's contents in another method, I have a bunch of random numbers, rather than what I assigned.

    PHP Code:
    class myClass

    public: 
        
    myClass();    
        ~
    myClass(); 
        
    void PrintContents();
    private: 
        
    int myArray[32];
    }; 
    PHP Code:
    myClass::myClass()
    {
        for ( 
    int i 032++)
        {
            
    myArray[i] = 0;
            
    cout << << " = " << myArray[i] << endl;
        }

    }

    void myClass::PrintContents()
    {
        for ( 
    int i 032++)
            
    cout << << " = " << myArray[i] << endl;

    Any tips or references? I know my array will always be 32 (0-31) size, so I didn't want to use a vector unless there isn't anyway for me to use a simple array.

    thanks,
    -Shurijo

  2. #2
    Hyperactive Member Comreak's Avatar
    Join Date
    Feb 2001
    Location
    Dis
    Posts
    319
    That's strange, the code works fine for me. What compiler are you using?
    C.O.M.R.E.A.K.: Cybernetic Obedient Machine Responsible for Exploration and Accurate Killing

  3. #3
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    Are you sure the object you're accessing later is the same one?
    an ending

  4. #4
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    If you are using MSVC++6, you might have to do a Rebuild All and then compile. I know that it chokes every once in awhile.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Posts
    164
    Thanks for the replies. I tested it out here at work and it works fine, too. I guess my compiler got hung up, I'll have to try it again when I get home.

    btw, I'm using VS 2003.
    -Shurijo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width