classes for a newbie
Hello
I am new to gamedevelopment and I am learning C++. I am reading a book about it and now it's about classes. But they describe classes very bad in the book. I have read it 10 times and I still don't know the use of them and HOW to use them. Maybe someone can explain it to me or knows a good website/tutorial.
you talk the talk, but do you walk the walk
[edited by - White Crow on March 6, 2003 4:28:34 PM]
~~~~~~I'll make you an offer you can't refuse...
First, forgive me for the formatting...
The easiest way to think of classes is that they are just custom data types. Instead of type int,char,float,etc. you can have types like Box,Spaceship,Frog, etc. These custom types can have data members and function members. Here's a simple class:
Now in your program you can do things like this:
[edited by - SpaceRogue on March 6, 2003 4:54:43 PM]
The easiest way to think of classes is that they are just custom data types. Instead of type int,char,float,etc. you can have types like Box,Spaceship,Frog, etc. These custom types can have data members and function members. Here's a simple class:
Class Frog{public:int Flies_Eaten; // A data membervoid Eat_fly() //A function member{Flies_Eaten++;}Frog() //Class contructor - Run when a new variable{ //of type Frog is created (called an instance)Flies_Eaten=0;}virtual ~Frog(){ //Class Destructor called when a Frog is deleted} //or goes out of scope};
Now in your program you can do things like this:
Frog Kermit; //Creates an instance of Class frogcout << Kermit.Flies_Eaten<<endl;Kermit.Eat_Fly(); //Increments the variablecout << Kermit.Flies_Eaten << endl;
[edited by - SpaceRogue on March 6, 2003 4:54:43 PM]
Ok a class is used to wrap up a specific process. Also lets you have private data members (data that cant be accessed by the program directly or from other sources) and adds cross compatiblity among your programs.
There is no REAL EASY way to introduce you to Classes, as they encompass alot. And if I personally tried, I would probably confuse you alot more
Here''s a LINK to a good tutorial I just found for ya.
There is no REAL EASY way to introduce you to Classes, as they encompass alot. And if I personally tried, I would probably confuse you alot more
Here''s a LINK to a good tutorial I just found for ya.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement