Can I create an array of pointer with new operator?
Printable View
Can I create an array of pointer with new operator?
Yes. Where are you having trouble?
I'm sorry. Because I've just learned C++, I'm still confuse about pointer in C++. Would you like to tell me how to create a pointer of array with new operator?
Type **ptr_array;
ptr_array = new Type *[256];
I'm not sure exactly what you want, so here goes...
A dynamically created array of int pointers:
int **myArray = new int*[10];
A dynamically created array of ints
int *myArray = new int[10];
Clarify what you want, try coding it yourself, and post your attempt here if you have trouble.
Can somebody tell me if this is correct, too ?
It seems to work but looks differnt then the code posted here. It wouldn't be too cool if it only worked because there are no overflow checks etc.Code:typedef int* pint;
pint *ppiRowIndices;
....
ppiRowIndices= new pint[iCount];
basically you did the same thing. the typedef gives a name to an int * is the only difference.
I did that because new didn't accept the "int*". :confused: Thats why I wondered if my code is correct. pint is just another name for "int*", so why would it accept that but not "int*"? Anyway, if it's correct and it works I'm happy. :)Quote:
Originally posted by FillYourBrain
basically you did the same thing. the typedef gives a name to an int * is the only difference.
thanks!
what compiler? can I see that line of code?Quote:
I did that because new didn't accept the "int*".
Also, once you have your array, remember that none of those pointers have been initialized.
Thank you. It's very helpful for me.
I understand the workings of an array of pointers, but I'm not sure about the application of it. Would this be a valid example?
I'm really lost here!Code:void InitializePCharArray(char **array,int num)
{
for (int i=0;i<num;i++)
*((&array)[num])=GetInput(); //return type char *
}
int main()
{
char **PPCharArray=new char*[10];
InitializePCharArray(PPCharArray,10);
return 0;
}
:p Wow that was some serious overkill ey? I think I understand now, I drew a whole lot of diagrams out on paper, with arrows, boxes, and everything.