Classes are definitions for abstract objects. They essentially allow you to define your own datatype, what values it stores, and what operations you can do on those values.
I'm not sure about Pascal/Delphi since I have no experience with that. In C++/Java/C#, classes have a constructor to initialize the data within them. They also have methods, which are special functions that you call on that object. Finally, they have instance variables that store basic data
types.
The important thing with classes (on a basic level) is data protection, also known as encapsulation. Data can be declared either public, private, or protected. Protected has to do with inheritance. Public is accessible outside of the class object. Private is only accessible by the object
itself.
That's pretty much a basic nutshell...here's an example of a C++ class.
class TestClass
{
public:
TestClass(); //The constructor, same name as the class
void printData();
int retrieveData();
void setData();
private:
int theData;
};
Notice that this is just a header file. In eoserv, header files are .hpp files and contain all the declarations. The implementations are contained in the .cpp files and provide instructions on what the class prototype should do when it's methods are called.
Destructors are the last bit I think you should know. They have to do with dynamically allocated memory (pointers). Other languages like Java and C# have a garbage collector that takes care of this for you, but in C++ you have to do it yourself (gives you more control and decreases overhead).
The default destructor is implemented by default by the compiler and clears up all the memory that isn't being dynamically allocated (it's there, so you don't need to write a destructor if you don't have any pointers).
---
class EOSERV {
Programmer | Oldbie
Open source EO Client: https://github.com/ethanmoffat/EndlessClient
};