2 game development interview summary

Summarize some frequently asked interview it

 

1: chat virtual function bar

In C ++, a virtual function is to achieve polymorphism, in a nutshell is a pointer to the parent type subtype of example, and then to call a member of the subclass pointer by parent class.

Each class contains a virtual function have at least one virtual function table corresponding thereto, the storage of this class of function pointers corresponding to the virtual functions are run.

 

Virtual function table in the process of building the steps of:

  1: copy of the base class virtual function table

  2: Alternatively overridden virtual function pointers

   3: an additional virtual function pointer subclass

These steps are completed compiler

 

2:

Virtual destructor: virtual destructor such that when the base-class pointer remove subclass object can call the destructor for the purpose of releasing subclass subclass heap memory, memory leaks

When the pointer delete parent class, since the destructor destructor subclasses and superclasses polymorphic forms, so to call the destructor subclass then calls the destructor of the parent class .

Pure virtual function: in the form of virtual void fun () = 0; need not be implemented, because it would not be called into

Abstract base class: classes with at least a pure virtual function, abstract base class can not produce objects reclassified, but may have a pointer to the class or referenced; pure virtual functions must implement a subclass or the subclass is the abstract base class

3:

Chat heap sort it

Heap sort is divided into two steps:

  1: the initial input data for the initial heap formed HeapAdjust

    Complexity is O (n), comprises a compare and swap formula can be written as s = 2 ^ (i - 1) * (k - i), 2 ^ (i - 1) denotes the number of elements in the layer, (k - i) represents the number of trees to be cut relatively child. Can obtain S = 2 ^ k -k -1, log (n) = k into the resulting S = n -lgn -1

  2: heap sort through the object exchange and readjust

    Complexity is O (nlgn) log2 + log3 + ... + logn ≈ log (n!) Are of the same order and function nlogn

Heap of scenarios: to find TOP K, implement priority queues. .

 

Guess you like

Origin www.cnblogs.com/amadios/p/11520662.html