Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Classes..?

Author
Message
Murloc
15
Years of Service
User Offline
Joined: 28th Dec 2008
Location: Utena,Lithuania
Posted: 18th Jan 2009 10:41
Yes I know that could be the most stupid question ever,but I don't understand what it is.
I know that funtions can return something or be void.
But what classes are?

PS. Yes,I have tried LearnCPP tuts,but I need normal explanation.

Thanks in advance!

Kinda noob,Murloc.

Theory-When you know everything,but nothing works.
Practice-When everything works,but you don't know why.
Programming merges these two-Nothing works,and you don't know why.
tomtetlaw
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location:
Posted: 18th Jan 2009 11:19
classes are a sort of container for data and functions heres an example:

class MyClass
{
private:
//private means only this class can access the things in here
//private functions or data goes here
protected:
//protected means friend functions or inherited classes can accsess the things in here
//public functions or data goes here
public:
//public means anything can accsess the things here
//public functions or data goes here
};

you can also try these links:
this is the best class tutorial i have ever seen and is the one i learnt from:
http://download.microsoft.com/download/d/b/b/dbb6dfc2-4d18-44c7-8402-cc546c9203a6/C++%20Beginner's%20Guide%20CH08.pdf

next part:
http://download.microsoft.com/download/d/b/b/dbb6dfc2-4d18-44c7-8402-cc546c9203a6/C++%20Beginner's%20Guide%20CH09.pdf

final part:
http://download.microsoft.com/download/d/b/b/dbb6dfc2-4d18-44c7-8402-cc546c9203a6/C++%20Beginner's%20Guide%20CH10.pdf

as you can see, there is alot to say about classes, but when you learn about them you'll find them really useful.

hope this helps.
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 18th Jan 2009 11:33
When you come to think of it, they are hard to descirbne, so ill give an example. Say I wanted to record loads of enemies for darkGDK, say space ships. now each of these ships needs a speed, a direction, and a weapon, as well as an integer to connect it to the GDK model. It needs to be updated every frame.
We can use a class to hold all this data, something like this:

Now we can use this class as if it were a datatype:

To access members of these objects, we use the . operator, or for pointers, ->
EG:

A struct is like a class, except that it contains no functions, only values.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 18th Jan 2009 17:45
To expand on Jezza's explanation, the advantage of using a class is the re-usable code. If you had three enemies to define without classes you'd have to declare (being brief here):

int enemy1x;
int enemy2x;
int enemy3x;
int enemy1dir;
int enemy2dir;
int enemy3dir;
and more stuff

Imagine updating each of these. You'd have to write code for each enemy. Now imagine doing it for hundreds of enemy. Exhausting.

With a class you declare the enemy by name or might spawn it in an array or vector. Each one of the enemy objects would have its own information self-contained and each frame you have the enemy object update itself rather than having to write code to address each one.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 18th Jan 2009 18:54
Quote: "A struct is like a class, except that it contains no functions, only values. "


Actually structs are almost identical to classes, except members of structs are public by default whereas they're private by default in classes.

jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 18th Jan 2009 19:22
Yeah, but people tend to use structs for functionless classes. and for good practice, you should always explicitly state public and private anyway.

bad

good

So in that respect, they are identical.
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 19th Jan 2009 04:45
It's declared in the C++ standard that class members are private by default, so I wouldn't exactly say it's bad practice not explicitly stating the private keyword in a class.

Login to post a reply

Server time is: 2024-11-25 11:38:25
Your offset time is: 2024-11-25 11:38:25