- C++ Keywords mutable: in const member function of class, if some members would like to change. Declare the member with key word mutable, it can be changed in const memeber function.
volatile: to avoid compiler optimization and can be changed from memory. The data will read from memory not cache or registers.
struct vs class: access mode. struct has public members by default. class has private members by default. Both of them have inheritance, public, private and protect.
virtual inheritance: B, C inherite A, if D inherited from B, C. To resolve the two inheritance from A, using virtual inheritance.
protected: derived class can access the inherited members. But in private, the inherited class can not access to this.
encapsulation: data is accessed by methods not directly modified (private, protected). Combine data and methods together.
inline: running faster than normal member function. Compile time will add tag for getting the function. Not run time.
pure virtual function: virtual void show() = 0;
static member: has same value through all objects. And can be accessed by class name.
function overloadding: same function name with different parameters.
reference vs pointer: oth references and pointers can be used to change local variables of one function inside another function. Both of them can also be used to save copying of big objects when passed as arguments to functions or returned from functions, to get efficiency gain. Despite above similarities, there are following differences between references and pointers. References are less powerful than pointers 1) Once a reference is created, it cannot be later made to reference another object; it cannot be reseated. This is often done with pointers. 2) References cannot be NULL. Pointers are often made NULL to indicate that they are not pointing to any valid thing. 3) A reference must be initialized when declared. There is no such restriction with pointers Due to the above limitations, references in C++ cannot be used for implementing data structures like Linked List, Tree, etc. In Java, references don’t have above restrictions, and can be used to implement all data structures. References being more powerful in Java, is the main reason Java doesn’t need pointers. References are safer and easier to use: 1) Safer: Since references must be initialized, wild references like wild pointers are unlikely to exist. It is still possible to have references that don’t refer to a valid location (See questions 5 and 6 in the below exercise) 2) Easier to use: References don’t need dereferencing operator to access the value. They can be used like normal variables. ‘&’ operator is needed only at the time of declaration. Also, members of an object reference can be accessed with dot operator (‘.’), unlike pointers where arrow operator (->) is needed to access members.
friend class: use methods not details and feature. Can be good for customers and boss.
dangling pointer: can be solved by share_ptr, and this is evil. The program will crash when meeting with dangling pointers.
- Reference C++ basic tutoral: https://www.tutorialspoint.com/cplusplus/cpp_storage_classes.htm C++ interview question: https://www.careerride.com/C++-Interview-questions-Answer.aspx
