| |||||||||||
|
Main Menu Other |
Tutorials -- Working with Objects | ||||||||||
|
Defining Classes and Making Instances of themFirst off lets go over the syntax of a class definition. The greyed out text is optional and is only used in certain cases.
class CLASSNAME : public DERIVEDCLASSNAME {
public:
int VARIABLE;
float VARIABLE;
void FUNCTION();
};
In the above code, the words in all caps are those specific to the class. Here's a listing of what they mean.
Each instance of the class you create contains the variables and functions of that class. Also, if you define a subclass of a class, it too will contain these variables and functions without having to redefine them. Referring to the blueprint-house analogy mentioned earlier: a blueprint isn't a house. You have to make a house based on the blueprint for it to be anything. Similarly you have to make an instance of a class in order to do anything with it. Here's how we'd make an instance of CLASSNAME: CLASSNAME InstanceOfClassName; Now if we can set InstanceOfClassName.VARIABLE = 1 or execute the function InstanceOfClassName.FUNCTION(). Lets go ahead and introduce my patented BasicObjectTM class. This one includes all the stuff you'll need to make an object in 3d space, position it, and give it velocity and acceleration.
|
|||||||||||