Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Mild Request] Help with classes

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Wed Jul 22, 2009 11:10 pm    Post subject: [Mild Request] Help with classes Reply with quote

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 Sad

Alternatively, if someone wants to write a small example(maybe as a wrapper, not so sure myself), that would be awesome as well. Embarassed

Thanks for any help , manc.

[P.S.] - C++ Confused

_________________
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Wed Jul 22, 2009 11:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Thu Jul 23, 2009 12:00 am    Post subject: Reply with quote

Thanks lurc Razz
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. Cool

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Jul 23, 2009 12:35 am    Post subject: Reply with quote

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
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Thu Jul 23, 2009 5:12 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites