|
-
Jun 4th, 2004, 12:44 AM
#1
Thread Starter
Addicted Member
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 = 0; i < 32; i ++)
{
myArray[i] = 0;
cout << i << " = " << myArray[i] << endl;
}
}
void myClass::PrintContents()
{
for ( int i = 0; i < 32; i ++)
cout << i << " = " << 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,
-
Jun 4th, 2004, 12:58 AM
#2
Hyperactive Member
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
-
Jun 4th, 2004, 04:19 AM
#3
Fanatic Member
Are you sure the object you're accessing later is the same one?
-
Jun 4th, 2004, 10:14 AM
#4
Fanatic Member
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.
-
Jun 4th, 2004, 10:46 AM
#5
Thread Starter
Addicted Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|