EOSERV Forum > Lounge > type class?
Topic is locked.
Page: << 1 >>
type class?
Author Message
Post #78732 type class?

I was just wondering if someone could shed some light as to what a 'class' is in delphi or any other language idk xD I was just going through the source code of kalandra and I understood most of it from studying pascal except the type class D:?!

Example
type
  TServer            = class;

Thanks in advance
~Dan

---
If money doesn't grow on trees, then why do banks have branches?
14 years, 5 weeks ago
Post #78734 Re: type class?


A class is an object. in C++ an object has its own variables and functions for each respective instance. Im pretty sure that holds true for the majority of OO (object oriented) langauges.

---
Love you too.
14 years, 5 weeks ago
Post #78759 Re: type class?

So a class constructor like initializes the class? then when you want the class to be erased from the temporary memory you make a class destructor? Ahh confusing!

---
If money doesn't grow on trees, then why do banks have branches?
14 years, 5 weeks ago
Post #78917 Re: type class?

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
};
14 years, 5 weeks ago
Page: << 1 >>
Topic is locked.
EOSERV Forum > Lounge > type class?