C ++ game development to prepare the basis of reviewing (a)

C ++ basics of game development, the main language is C ++, almost a year out of school, to take this opportunity will soon forget the look back at it again, but also sort out the interview and other relevant knowledge.

First of all, C ++ fully supports object-oriented (Note 1) programming, including object-oriented development of the four properties (some people say three characteristics, not abstract):

  • Package
  • abstract
  • inherit 
  • Polymorphism

Encapsulation, refers to a subject have a clear boundary; division border (objects perform their duties, the reusability of object size, object), the object of the method is declared public, but the process of implementing the method are hidden, the advantage of this is that when the object to modify their own method of implementation, the program will not affect the use of the object.

Abstract, a set of abstract objects having the same or similar properties is Class A, is a class of things description, abstract, conceptual meaning. Abstract object of the class, object class is concrete, it can be said that an object instance of a class. Class is used to describe a series of objects, each object data is summarized to be included, and outlines the behavioral characteristics of each object.

Inheritance, the relationship between father and son, on the common parent class, subclass personality in each sub-category at the same time retain their own personality, inherited the common parent class. In layman's terms, the parent class to the child class, that is, from the general to the particular. C ++, inheritance single inheritance is that each subclass can only inherit from a parent, but a parent can have multiple children classes.

Multi-state, multi-state operation.
  Subclasses of the object in reference to the parent class, for example, Animal a = new Dog, subclass object as a parent class object used.
        1. Polymorphic principles:
                  (1) the same type of object
                  (2) method of the type defined which reference can only be called by reference
                  (3) is running, then to find a method of subclasses based on the actual type of the object covered
             examples:
                  There there are two methods in class Animal eat () and sleep (), sleep sleep () for 8 hours; there is a subclass of Dog
                  eat () method, sLEEP () method, six hours of sleep, there wangwang () method.
                  Now create Animal a = new Dog (); can not call a.wangwang (); call a.sleep () outputs six hours of sleep.

          2. The cast object
                 format: instanceof reference type
                        references a class object referred to match the value returned boolean value.
                 Usage:
                       Animal A new new Cat = ();
                       IF (the instanceof A Dog)
                       {
                          Dog d = (Dog) a;
                          d.wangwang ();
                        }
                 Note: If only Dog d = (Dog) a; run-time error, because a is not Cat Dog (first principle polymorphism)

          3. Multi flexible conversion state
                  (1) for a list of parameters:
                               public void m (a a) {} as parameters any child class object class a
                  (2) in the return value:
                              public m a () {} this the method may return any subclass of class a

 

 

Note 1: The difference between the object-oriented and process-oriented

Process-oriented analysis is a required step to solve the problem, then use the function to implement these steps, step by step, when used in a call to a turn on it.

Object-oriented transaction is to be a problem down into objects, the object was not intended to establish a complete step, but a thing to Miao Xu behavior throughout the problem-solving steps in.

Guess you like

Origin blog.csdn.net/qq_37243013/article/details/90649470