Jump to content
  • Advertisement


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


C++ way for C thing

This topic is 5754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!