Jump to content
  • Advertisement


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


Public members vs. TypeDef Struct

This topic is 6598 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

I have seen all DirectDraw stuff encapsulated within a structure. I was thinking of putting everything in a class with all public members. I know these are essentially the same. Which is better programming practice? --Chris

Share this post

Link to post
Share on other sites
It is better programming practice to leave it like it is otherwise you will create bloatware and use unnessicary code.


A wise man once said "A person with half a clue is more dangerous than a person with or without one."

Share this post

Link to post
Share on other sites
I would put it in a class.......
put all data members as private and provide public member functions that allow the manipulation of the private data members....why do this ?
say if you have a class called DDSurface.....for data members you have LPDIRECTDRAWSURFACE7 mySurface;
you could make this public, but in this case whoever is using the class could manipulate the surface in some harmful way....like accidentally deleting it or something like that when the only thing you intended for it to do was draw to the surface......
so instead make a function
HRESULT DDSurface::drawToScreen(xPos, yPos);
that will let whoever is using the class to draw the surface to the screen and keep them from doing harmful operations on the private data member while at the same time all they have to do is call this function to draw to the screen.......
instead of......

BltFast->something->something(bunch of variables);
do some other stuff and error check;

........to draw something

"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Share this post

Link to post
Share on other sites
There''s no different between using a struct and a class with all public members. They function the same. Although making all public members mean you miss out on a lot of the benefits of classes. Perhaps read up on object orientation before you start throwing things haphazardly into classes in the name of ''good programming practice''.

By the way, you don''t need to typedef a struct in C++. Just name it whatever you want it to be called, eg:

struct MyStructName
// members

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!