|
-
October 11th, 2002, 07:51 PM
#7
Here....
Code:
#include <windows.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>
int main(int _argc,char * _argv[]) throw()
{
srand(::GetTickCount());
int *** pPointerToPointerOfPointers = new int **[10];
for (int i = 0; i < 10; ++i)
{
pPointerToPointerOfPointers[i] = new int *[10];
for (int x = 0; x < 10; ++x)
{
pPointerToPointerOfPointers[i][x] = new int(rand());
}
}
for (int p = 0; p < 10; ++p)
{
for (int q = 0; q < 10; ++q)
{
std::cout << "The value of at index " << q << " of the index " << p << " is " << *(pPointerToPointerOfPointers[p][q]) << std::endl;
}
}
// deletion
for (int r = 0; r < 10; ++r)
{
for (int s = 0; s < 10; ++s)
{
delete pPointerToPointerOfPointers[r][s];
}
delete [] pPointerToPointerOfPointers[r];
}
delete [] pPointerToPointerOfPointers;
return 0;
}
That answers the question - using new and delete to accomplish this. (The question was not about std::vector - although, that is a viable solution to what he wants to do - but he asked for new/delete) It is best to answer how to do something, the way the person asks how to do it - that's what he asked for. In this case, it's a question of C++ logic - knowing the answer and understanding how it works will make a better programmer.
Last edited by JamesSchumacher; October 11th, 2002 at 08:13 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
|