I want to create an array of rectangles. How would I got about doing this? Do I create an array of RECT? are there other ways?
I want to create an array of rectangles. How would I got about doing this? Do I create an array of RECT? are there other ways?
the best things in life are simple.
Use RECT with win32, CRect or RECT with mfc; other class libraries may have similar structures/classes defined for use. How you set up your array is entirely up to you. Here's 3 possible ways:
RECT rc[100];
const int NUM_RECTS=100;
RECT *rc=new RECT[NUM_RECTS]; /*...and later*/ delete[] rc;
#define NUM_RECTS 100;
RECT *rc=(RECT*)malloc(sizeof(RECT)*NUM_RECTS); /*...and later*/ free(rc);
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
There is no other way.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
>>There is no other way.<<
Future proofing.
Well its the same as any other data type. Do you know how many you need before hand or at run-time?
If you know how many you need then you can do it like this:
Or if you find out a run-time..Code:// An array of 5 rects RECT myRects[5]; int i; // Set a certain rect to something for( i = 0; i < 5; ++i ) { SetRect( &myRects[i], 10, 20, 30, 40 ); }
Code:// Assume nRects is initialized to number of RECT's we need RECT *pRects = NULL; int i; pRects = new RECT[ nRects ]; if( pRects == NULL ) { FatalAppExit( 0, "Out of memory" ); } // Setup the rects for( i = 0; i < nRects; ++i ) { SetRect( (pRects + i), 10, 20, 30, 40 ); } // Free memory delete [] pRects;
Thanks!
Well, i want to build a cellular automata program (Conways game of life) so I'll have a set amount of rectangles before hand.
Thanks again!
Last edited by xlnk; 12-18-2002 at 07:34 PM.