 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Wed Jul 22, 2009 11:10 pm Post subject: [Mild Request] Help with classes |
|
|
I understand the syntax of classes, how to declare them, and how to declare an object or instance of them. What I do not understand is the REASON or the purpose of using classes. I've been trying to learn them for a few days now, but every tutorial I find just talks about syntax and constructors, destructors, etc. Someone told me that they were for making wrappers easy to make, and so on. Basically, to me they just seem like retarded structs that try to complicate things. I don't see the point of making things private when I'm the only one touching my code anyways. Can someone clarify?
If anyone has any more insightful links that explain the purpose of classes and how to use them, that would be great
Alternatively, if someone wants to write a small example(maybe as a wrapper, not so sure myself), that would be awesome as well.
Thanks for any help , manc.
[P.S.] - C++
_________________
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Wed Jul 22, 2009 11:51 pm Post subject: |
|
|
Classes are in-general the same as structures, but the only difference is the ability to do more then access variables. Unlike a structure you can declare methods, constructors, destructors, etc.
The reason classes are so widely used is because of they act as there own little space. Instead of having 50 functions all having to do with different tasks, classes group certain tasks together. In a certain aspect they provide a certain structure to things kind of like namespaces do, but classes are more dynamic.
Like for instance if you wanted to store an array of students names, grades, averages, etc.
Functionally speaking we'd declare arrays of variables such as:
#define STUDENT_COUNT 3
LPTSTR lpszNames[STUDENT_COUNT];
DOUBLE dMarks[STUDENT_COUNT][4]; // Four marks per student.
DOUBLE dAverage[STUDENT_COUNT];
DOUBLE CalculateAverage() { ... }
Now using an object we can do this:
class Student
{
LPTSTR lpszName;
DOUBLE dMarks[4];
DOUBLE dAverage;
DOUBLE CalculateAverage();
};
Then in our code provide an array of students.
Student *students[4];
Now these things are pretty much the same thing, the only difference is the how the code is wrapped.
Functionally the function is out in the open, and all the variables are available the the source file, but what if you wanted the variable to be accessible to anyone who includes the header file? This is where classes also have an upper hand, instead of having to make a get function to retrieve the variable from the source code you simply can make the variable public in a class and retrieve it.
Classes just simplify certain aspects of coding, although some things I like to stay clear of objects.
_________________
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Thu Jul 23, 2009 12:00 am Post subject: |
|
|
Thanks lurc
I never really thought of having other people use my header files, that's why it wasn't too apparent to me.
Definitely helped though.
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Jul 23, 2009 12:35 am Post subject: |
|
|
| lurc wrote: | Classes are in-general the same as structures, but the only difference is the ability to do more then access variables. Unlike a structure you can declare methods, constructors, destructors, etc.
|
If I remember right, structs are created on the stack normally, but classes are created on the heap.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Thu Jul 23, 2009 5:12 am Post subject: |
|
|
| it depends how you do it. whether you create it locally or dynamically by allocating memory. that is for structs at least. not sure about classes. i think classes are created dynamically by allocating memory as well though
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|