Advertisement

What are classes?

Started by March 15, 2002 03:13 AM
19 comments, last by Mage_gr 22 years, 8 months ago
Can somebody explain me what classes are in VC++?
When you see a roller coaster, get on it,put your hands in the air,and ride it to the very end.Life doesn't remember you unless you kick,scream,and claw your way to the top.There is nothing in the world that is impossible.If you believe that you can do it, you will.
I`m not going to put a definition on this, but just a simple explanation:

Classes are a perfect way of separating data and procedures manipulating on those data. What does it mean ? Your program shall have several subsystems working (e.g. sound, input, AI, terrain renderer, character renderer,...) and each subsystem is separated from others. It means that every subsystem shall have its own variables and procedures and they can have the same name and are distinguished just by the name of the class they belong to.
Also it is great for debugging and finding errors, since you can specify whether variables (data) and procedures (methods) shall be global (public) or local (private). It means that you can easily find out the source of potential problems (i.e. who has changed the data, and many more).
It`s great for readibility. Usually classes are grouped into header files, so you can always easily find the class definition and you don`t have x hundreds lines of variables definitions in the beginning of the main program. There are many other reasons for readibility and clarity, but you`d better get some book on this.
Well, there might be a performance penalty associated with classes, but with clever usage (not putting whole classes onto stack, and so on) this is not a big issue.

These are just few of the reasons why classes are good. There are books that teach classes on three hundreds pages, so they are definitely huge, but you need to understand only first few 50 pages regarding the classes and you can use them. Of course there`s a lot of info for polymorphism and heritage, but that`s another story.

Simply put, I think that classes are the best thing that could meet the C language and big projects.

VladR My 3rd person action RPG on GreenLight: http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

Advertisement
A class is just a polished struct

The only major difference between a struct and a class is that you can specify access rights to its fields and methods
(the ''private'', ''protected'' and ''public'' keywords).

Have a nice day,



---
Never trust a Troglotroll.
---Never trust a Troglotroll.
So, you mean that you can''t specify access rights within a struct, then?
No... to my knowlegde you cannot use keywords such as "private" or "protected" in a structure. Anyway, it wouldn''t make any sense
http://acecorp.free.fr
quote: Original post by SabreMan
So, you mean that you can''t specify access rights within a struct, then?


Ouch. You''re true, I was wrong.... Sorry... Mea culpa...

You can specify access rights for structs as well.
The only difference is that struct members are public by default.
Otherwise structs are really the same as classes.

Have a nice day,



---
Never trust a Troglotroll.
---Never trust a Troglotroll.
Advertisement
quote: Original post by Ace17
No... to my knowlegde you cannot use keywords such as "private" or "protected" in a structure. Anyway, it wouldn''t make any sense

Why wouldn''t it make any sense?
Do structures have constructores and destructores and static methods and member values?
Do structures have constructores and destructores and static methods and member values?
AP - yes, but I think I''d slap anyone that was using a struct where a class should be used.

This topic is closed to new replies.

Advertisement