|
"Too Clever For Your Own Good"
|
|
USING CLASSES IN C++ PROGRAMMING |
|
Classes: Glossary of Terms A class is a template from which you create objects. The class combines data and functions into a single entity. An object is an instance of a class -- like a variable, but more complex. Data members are variables that are part of a class. Methods are functions that are built into a class (and which are therefore built into all objects created from that class). Inheritance is the process of deriving a class (the derived class) from another class (the base class). All data and methods from the base class are available to the derived class. The derived class can override data and methods inherited from the base class. The derived class can also introduce data and methods not found in the base class. Encapsulation is the principle of combining data and functions into a single unified entity, the object. An object may have any number of data members and functions, but this complexity is encapsulated within an object, for ease of use. C++ is a complex language ... the above glossary is merely an introduction.
|
|
Classes in the Half-Life SDK - The SDK is made up of numerous classes. Here's a quick introduction to the CBasePlayer class: Open up HL.DSW (server code) in Visual C++ (VCPP), and find the code for the CBasePlayer class definition, which looks like this:
Examine the various elements of the above code:
Except for top-level classes, all classes are derived from other classes. Let's trace the inheritance of the CBasePlayer class. In VCPP, right-click on CBaseMonster, and select "Go To Definition" from the pop-up menu. VCCP displays the CBaseMonster definition:
Notice how CBaseMonster derives from CBaseToggle ... the definition for CBaseToggle looks like this:
CBaseAnimating, in turn, derives from CBaseDelay ...
Similarly, CBaseDelay derives from CBaseEntity
CBaseEntity is the top-level class, from which all other entity classes are derived. It starts like this:
In this hierarchal class scheme, the top-level class contains the simplest, most general definitions. Each of the derived classes adds another layer of complexity. When hacking the SDK, you can leverage existing code by deriving new classes from existing classes. Don't re-invent the wheel ... borrow a copy of the wheel, and make it better! |
|
Using
Classes in C++
|
|
"Handy
Vandal" and "Handy Vandal's Almanac" copyright 2008 by
Karl Gregory Jones Half-Life © 1998-99 Sierra On-line and Valve L.L.C. All rights reserved. Half-Life and the Half-Life logo are trademarks of Sierra On-Line. Valve and the Valve logo are trademarks of Valve L.L.C. Half-Life images, textures, music, sound effects, and other graphic or audio content © 1998-99 Valve L.L.C. All rights reserved. |