Skip to main content
GameDev.net gamedev.net
🔒 Locked

An array of pointers?

Started by Subotron Apr 24, 2003 at 9:06 AM 2 replies 250+ views
Original Post
Subotron
Subotron
Hmm I''m confused. I know how to work with arrays and pointers, but I can''t seem to combine them. I have things like this: CClass* g_pPointer = NULL; g_pPointer = new CClas(); g_pPointer->DoFunction(); but now I want to create an array of pointers. What would be the correct way to do all this for an array of pointers? Thanks in advance for the help. | Panorama 3D Engine | Contact me | | MSDN | Google | SourceForge |
Qw3r7yU10p!
Qw3r7yU10p!
CClass* pointers[50];

or

#include <vector>
std::vector<CClass*> pointers;
Subotron
Subotron
Hmmm okay thanks the first way seemed the most obvious one to me, that''s the one I tried. But the problem is the 2 other lines of code I posted don''t work with an array (the first one doesn''t initialize the whole array I think and the second one should only do the function for one of the class pointers so I should also be able to specify which of the class pointers should do the function. For the ''new'' command I had no clue, with the function I tried g_pPoiner[number]->DoFunction(); but it didn''t seem to work.

| Panorama 3D Engine | Contact me |
| MSDN | Google | SourceForge |
rypyr
rypyr

CClass* arrptrs[10];

for(int loop = 0; loop < 10; ++loop) {
arrptrs[loop] = new CClass();
}
arrptrs[4]->DoFunction(); // call the 5th object''s DoFunction()

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.