|
-
February 24th, 2009, 11:18 AM
#1
[RESOLVED]Storing Objects in an Array
Hi,
Thanks for the help earlier on on another problem, now for a new one....
I wish to store objects (I think I actually mean object pointers, but I am sure you will tell me if I'm wrong) in an array. Through my searching people seem to suggest the following:
MyClass *test[10];
test[0] = new MyClass();
test[1] = new MyClass();
// etc....
test[0]->add_info("foo");
test[1]->add_info("bar");
// etc....
cout << "Info for test0: " << test[0]->get_info();
cout << "Info for test1: " << test[1]->get_info();
Now, I have tried this and essentially each time I do an add_info call, it replaces my existing data - regardless of me choosing a different array index. (So, a test[1] add_info call, replaces the data in test[0] as well as test[1])
I'm sure that I am doing something utterly stupid here, would anyone mind telling me where I am going wrong??
Last edited by skycrazy123; February 24th, 2009 at 12:02 PM.
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
|