Array with pointers/adresses
Hia!
I was wondering how I would create an array with a pointer to an object no matter what object type it is... just simply put an adress in the array?
And I would also appreciate if someone could how to define this and dynamicly allocate memory with a "*array = new TYPE;" construction?
Thank you very much!
to do this all you need to do is create an array of void pointers. The declaration of that would be
void **MyArray;
and to allocate it with new you would simply do
void **MyArray = new void*[SizeOfArray];
hope that helps but remember that void pointers are an easy way to debug all day =-).
void **MyArray;
and to allocate it with new you would simply do
void **MyArray = new void*[SizeOfArray];
hope that helps but remember that void pointers are an easy way to debug all day =-).
ASCII stupid question, get a stupid ANSI
an array of void* would do the trick.
DaJero
- Oderint dum metuant
// Example#include <iostream>#include <string>using namespace std;int main(){ void* MyArray[10]; string *s = new string("Hello"); MyArray[0] = s; cout << *(reinterpret_cast <string *> (MyArray[0])) << endl; cin.get(); delete s; return 0;}
DaJero
- Oderint dum metuant
DaJero- Oderint dum metuant
quote: Original post by craftyIt means pointer-to-a-pointer. It means that MyArray contains an adress that is itself an adress i.e. the adress of the first object in the array. You can do a lot of neat stuff with things like this, but they''re hell to debug
What does it mean when you have two ** ... as in void**??
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement