Jump to content
  • Advertisement
Sign in to follow this  

c++ classes

This topic is 4004 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'm not quite sure of how classes work. what's the point of them? r they necessary? they don't seem to effect a project i'm working on if i don't use them, so why r they there? i'm just curious cuz it bugs the heck out of me with it being there and me not knowing what it's for. thanks in advance for any feedback

Share this post

Link to post
Share on other sites
The most obvious reason that classes are useful is the fact that they allow you to couple the idea of an objects data with its implementation. Also more advanced features are available through classes. These features include polymorphism, encapsulation, abstraction and inheritence. Thoes happen to be the key components of object oriented programming.

If you are not using these features thats fine, because object oriented programming is entirely equivalent to imperative techniques -- that is to say they can both be used to write code with the same functionality. However depending on the situation, object oriented programming can save you a lot of headaches and you're not using the language to its full potential.

Share this post

Link to post
Share on other sites
The thing that's always stuck with me most is this: Classes were made for your convenience, not the computer's. Can't remember who said it, but know that the whole point is to simplify your life.

It's inefficient to have these variables:

Why not have
class car

Isn't that so much easier to think of?

Now what if I want many cars?






Or I could just do this:

Using object often seems pointless when you're just starting out, but the truth behind the simplicity of object is that you can automate the process of building an object. More reliable, more readable, better. What if you needed one thousand cars? Classes make complexity simple.

As for how they work:
Well, basically a class is a list of variables that make an object, and a list of implementations. I believe (but don't quote me) that c++ has the variable of a class instance point to the first variable in the memory. If you want to use a variable in the class, c++ returns the variable at (the starting location + the size of all the variables before it). Might be hard to visualize just by me saying it. Get a piece of paper (I'm serious, get it) and draw a big rectangle. Draw four horizontal lines and the four rectangles in the bigger one should represent an integer. Draw eight more lines and they should represent a long int. I believe that's how the computer views a class, but don't quote me.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!