Study day 53

Time:2021-1-16

C++

  1. What is RTTI
    1. Runtime type recognition, enabling programs to use pointers or references to base classes to check the actual derived types of the objects that the pointers or references refer to
    2. Through dynamic_ Cast operator can change base class (parent class)Pointer or referenceSafe conversion to a derived class (subclass) pointer or reference
    3. TypeID operator, the actual type of the object to which the pointer and reference can be returned
    4. ==Base class must have virtual function, this is RTTI (dynamic class)_ Cast operator and typeID operator)
  2. dynamic_ Cast operator
    1. dynamic_ Cast (pointer object to be transferred);
    2. If the reference conversion fails, there will be STD:: bad_ Cast exception, catch exception try {normal code} catch (exception to catch) {exception}:
    3. It is similar to if else executing code first, then catch catching code exception, no code exception, normal execution, if there is code exception, then executing the code in {} and the {} brace after catch are just like the bottom of the story
  3. TypeID operator
    1. TypeID (type or expression)
    2. Returns a reference to a constant object, that is, type_ info
    3. cout<
    4. It is mainly used to compare whether two pointers point to objects of the same type
  4. type_ Info
    1. Standard library is a class
  5. RTTI and virtual function table
    1. If a class contains a virtual function, the compiler will generate a virtual function table for the class. The virtual function table is for the class, and each item in the virtual function is a pointer to the entry address of the virtual function
    2. The first table of the virtual function table points to the type associated with the class_ Info object

Recommended Today

New JavaScript syntax “double question mark syntax” and “optional chain syntax”

Double question mark grammar Double question mark grammarThe concept is to return the value on the right when the value on the left is null or undefined let Form = undefined ?? true; //Form = true Alternative chain syntax ? optional chain //Optional chain let body = { value: { a: ‘123321’ } } let […]