why should i use classes etc?
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 !
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!
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!
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
Mike Barela
mbarela@earthlink.net
Mike BarelaMikeB@yaya.com
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
class enemy
{
position[x,y,z]
orientation[x,y,z]
speed
state
etc
}
a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
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
Brian
aig
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.)
Classes have two things that structures just don''t have:
1. The ability to derive classes
2. Polymorphism
1. The ability to derive classes
2. Polymorphism
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.
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.
A polar bear is a rectangular bear after a coordinate transform.
Actually, Armitage, I''m pretty sure that structs are just like classes only in C++, they are not in straight C. So, it should be stressed that you are sort of MEANT to use classes if you want to use any real object oriented features...
Not that it really matters though
------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
Not that it really matters though
------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement