Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

White Crow

classes for a newbie

This topic is 5586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post

Link to post
Share on other sites
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:

Class Frog
int Flies_Eaten; // A data member

void Eat_fly() //A function member


Frog() //Class contructor - Run when a new variable

{ //of type Frog is created (called an instance)


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 frog

cout << Kermit.Flies_Eaten<<endl;
Kermit.Eat_Fly(); //Increments the variable

cout << Kermit.Flies_Eaten << endl;

[edited by - SpaceRogue on March 6, 2003 4:54:43 PM]

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!