- templates < inheritance < composition in terms of better usage frequency.
- as a static - does not keep state of the class instance.
- as a singleton - keep a universal state of a single class instance.
- as a base class - distinct states and fine-grain control of accessibility to its helper functions.
- Preventing redefinition of user-defined keyboards.
- A C++ framework should have at least one namespace to group all files.
- Compiler just add this constant string as prefix of variables.
4, Forward declarations
- Only used as pointer types.
- Behaving like void* but no need to cast.
- To solve ambiguous hierarchy composition (known as the "diamond problem")
- A particular base class in an inheritance hierarchy is declared to share its member data instances with any other inclusions of that same base in further derived classes.
- AMF_DECLARE_IID("AMFCFilter")
- Macro methods for getting current class name for debugging.
- Caller clean-up: cdecl syscall optlink
- Callee clean-up: stdcall fastcall register // AMF_STD_CALL informs compiler how to call.
- It overwrites this method pointer in class instance memory to point to a warning methods. The program terminates if the pointer is not overwritten and output warning.
- Basically pure virtual functions are required to be implemented in sub classes.
- Able to calling the corresponding virtual methods based on class instance memory instead of static pointer type.
- If B is a subclass of A: A* pA = new B(); pA->foo(); => invokes B's foo().
- base_class::foo(...)
- Unlike Java/C#: C++ does not have super or base keywords due to support of multiple inheritance.
- wchar_t: 2 bytes per char unicode - support minimum Chinese, Korean, etc.
- ANSI: 1 byte per char
- A *pA - dereference 1 time to get value.
- A **pA - dereference 2 times to get value.
- A ****pA - dereference 4 times to get value.
- int i = 0; int &j = i; compiler will replace j with i during compilation.
- Compare to pointer, reference could control size of an array. foo(int[4] &pA);
- static_cast is a strict explicit casting. (Make sure casting fine at compile time.)
- reinterpret_cast is a loose explicit C style casting. (You know what you doing or it fails.)
- const_cast converts const variable to be non-const variable. (Should not use unless its a hack.)
- dynamic_cast is the same as static_cast at compile time, but it also checks at runtime. (Never used)
- #ifndef #define #endif - C style
- #pragma once - C++ style
- TYPE& operator=()
- Only the above function signature matches then the overloaded methods is called.
17, Constructors vs Copy Constructors vs ...