< Previous | Contents | Next >
In this chapter, you should have learned the following concepts:
n Object-oriented programming (OOP) is a way of thinking about programming in which you define different types of objects with relationships that interact with each other.
282 Chapter 8 n Classes: Critter Caretaker
n You can create a new type by defining a class.
n A class is a blueprint for an object.
n In a class, you can declare data members and member functions.
n When you define a member function outside of a class definition, you need to qualify it with the class name and scope resolution operator (::).
n You can inline a member function by defining it directly in the class definition.
n You can access data members and member functions of objects through the member selection operator (.).
n Every class has a constructor—a special member function that’s automatically called every time a new object is instantiated. Constructors are often used to initialize data members.
n A default constructor requires no arguments. If you don’t provide a constructor definition in your class, the compiler will create a default constructor for you.
n Member initializers provide shorthand to assign values to data members in a constructor.
n You can set member access levels in a class by using the keywords public, private, and protected. (You’ll learn about protected in Chapter 9, “Advanced Classes and Dynamic Memory: Game Lobby.”)
n A public member can be accessed by any part of your code through an object.
n A private member can only be accessed by a member function of that class.
n An accessor member function allows indirect access to a data member.
n A static data member exists for the entire class.
n A static member function exists for the entire class.
n Some game programmers prefix private data member names with m_ and static data member names with s_ so that they’re instantly recognizable.
n A constant member function can’t modify non-static data members or call non-constant member functions of its class.