Archived

This topic is now archived and is closed to further replies.

Spadge

C++ way for C thing

Recommended Posts

Hiya all, I''m currently reading through Tricks of the Windows Game Programming Gurus and got to the part where the author gives you a function for creating a Direct Draw clipper and getting it working. I have a question about this (which I think looks ugly):
LPRGNDATA region_data;
region_data = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER)+num_rects*sizeof(RECT)); 
What is the C++ way to do this?Because for a starters I''d like to know, and secondly I''m going to be re-writing all his functions he gives you for doing DirectDraw into classes and such. I''ve consulted my C++ book but it only gives at most
new int 
, so on and so forth. Thanks in advance! Oh, and Happy Christmas! (Unless you don''t celebrate in which case; Happy December! Heh) ------- Spadge.

Share this post


Link to post
Share on other sites
LPRGNDATA region_data = (LPRGNDATA) new char [sizeof(RGNDATAHEADER)+num_rects*sizeof(RECT))];



What does God want?
Does God want goodness or the choice of goodness?
Is a man who chooses the bad perhaps in some way better than a man who has the good imposed upon him?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The C++ way would be to write a constructor that takes the number of rects as a parameter. Then, you''d do this:


MyRegionData* pointer_to_region_data = new MyRegionData(num_rects);


Alternatively, you could decide to create the object on the stack.

MyRegionData region_data = MyRegionData(num_rects);

Share this post


Link to post
Share on other sites