Can I create an array of pointer with new operator?
Can I create an array of pointer with new operator?
Yes. Where are you having trouble?
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
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];
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
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.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
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.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
I did that because new didn't accept the "int*". 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.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?I did that because new didn't accept the "int*".
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
Also, once you have your array, remember that none of those pointers have been initialized.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
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; }
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
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.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials