Jump to content
  • Advertisement

Archived

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

srmeister

why should i use classes etc?

This topic is 6697 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 must be a really lamer when i ask this question: why should i use classes ?I mean everything that classes can do, functions can also do it! I dunno if its possible to answer in a not-joking way but please try to describe it ! i am new to C++, i used C before !

Share this post


Link to post
Share on other sites
Advertisement
Heh, I''ll save the jokes for later

Anyway, member functions in a class allow each different class object you create to contain its own set of personal functions, that only act on itself, instead of a general function. Also, due to derivation, polymorphism, etc., classes can be real cool, and allow your code to be more efficient!

Share this post


Link to post
Share on other sites
From a purely design orientation classes are cool because you can view things as an object, just like you would in life. In the world you have a dog, a dog can eat, sleep and run. These are all functionality of a dog. That may not seem at first like a big advantage, but wait until you start working with lots of code. Having everything objectified makes it a breeze to use your code base with out confusion. If your moving from C classes will not take you that long to learn and will save you a lot of pain once you get used to them.


Mike Barela
mbarela@earthlink.net

Share this post


Link to post
Share on other sites
exactly. it''s an organization tool that simplifies everything during big projects like:

class enemy
{
position[x,y,z]
orientation[x,y,z]
speed
state
etc
}

a2k

Share this post


Link to post
Share on other sites
srmeister, I recommend getting a good beginning book on C++. They offer much more than just organization. There are several good tutorials on the net too, but for some reason they''re strangely absent from the gamedev.net programming reference section.

Brian

Share this post


Link to post
Share on other sites
Well, like the previous example classes are good for enemies, they can hold their data like speed, position, hitpoints. Structs can do that to, but with classes you can have functions in them, (like drawing them, running their AI etc.)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
structs can have funtions in them as well

Share this post


Link to post
Share on other sites
Classes have two things that structures just don''t have:
1. The ability to derive classes
2. Polymorphism

Share this post


Link to post
Share on other sites
That''s very very wrong, considering that a structure (struct) is the same thing as a class in c++, just that it defaults to public instead of private.
Note: The Very Same Thing.

Classes do a lot. Polymorphism. Inheritance. Data Hiding. Read a book, honestly. There''s simply too much.


A polar bear is a rectangular bear after a coordinate transform.

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!