Review of error-prone knowledge points for C++ final judgment/choice questions

1. Constructor and destructor can be inherited or take address (×)

2. The constructor can be overloaded, but there is only one destructor (√)

3. A function whose return type is a reference type can return a local variable (×)

4. Static member function does not have this pointer (√)

5. Static member functions can directly access non-static member variables (×)

//Because the static member function does not have this pointer, it cannot directly access the non-static member variable. You must pass the current object as a parameter to the function to access the member variable of the current object

6. Variables of const type can be declared without initialization (×)

7. Objects of const type can only access member functions of const type, except for constructors and destructors (√)

8. If an object of const type is used as an actual parameter, it can only be passed to a formal parameter of const type (√)

9. Objects of volatile type can only access member functions of volatile type, except for constructors and destructors (√)

10. When a composite class calls a constructor, the order in which the constructors of member objects are called depends on the constructor initialization list of the composite class (×)

//The order in which the constructors of the member objects are called depends on the order in which they are declared in the composite class

11. A class or a function of a class as a friend must be declared first and then used (√)

12. Friendship can be inherited (×)

//The friendship relationship does not inherit, do not pass, and is asymmetric

13. Overloaded functions allow only the return type to be different (×)

//Overloaded functions can be different in the number of parameters, parameter types, and whether they are const types, but if only the return value type is different, there will be ambiguity when calling the function

14. Operators that do not exist in C++ can be overloaded (×)

15. Operator overloading can change precedence (×)

16. Operator overloading does not change the number of operands (√)

17. Are there any operators that cannot be overloaded? : :: . # ## .* ->* *

18. Overloaded operators that return temporary objects have the suffix ++ suffix -- + - * / %

19. Overloaded operators whose return value is a reference type are prefixed with ++ prefix -- = [] () << >>

20. Operators that must be overloaded in friend mode are << >>

21. Operators that must be overloaded as member functions are = [] () ->

22. The derived class object can be used in any occasion where the base class object is used. For example, the derived class object can be assigned to the base class object, base class pointer or base class reference, but at this time the base class object, pointer or reference can only be accessed base class member

23. The definition of the class or base class where the member object is located needs to be included before the definition of the compound class or derived class

24. Execution order of constructors of derived classes: constructors of base classes (if they are all virtual base classes or none are virtual base classes, follow the order declared at inheritance) -> constructors of embedded member objects (declared in the class according to member objects order) -> the constructor of its own class

25. When a derived class object calls the constructor of its base class, if it has multiple base classes at the same level, the construction of the virtual base class is prior to the construction of the non-virtual base class

26. The virtual function prototypes of the derived class and the base class may be inconsistent (×)

//If it is only the same name, it is just an ordinary overload; if only the return value type is different, the program will go wrong

27. Virtual functions can be of static type (×)

//Static functions, inline functions, and constructors cannot be virtual functions

28. When an ordinary function calls a virtual function, what is actually called is the virtual function of the class pointed to by this pointer (√)

29. The virtual function is called in the constructor or destructor of the base class, and the virtual function of the base class is called (√)

30. Virtual properties cannot be inherited (×)

31. Two ways to achieve polymorphism: overloading and virtual functions

32. A pure virtual function is an empty function (×)

33. Matching principles for function calls:

① Find the exact matching function

② Match after function template instantiation

③ Overloaded function parameters match after implicit type conversion

④ When two or more matching functions are found in one of the above steps or no matching functions are found in the three steps, the program will go wrong

34. The destructor cannot be called actively (×)

// After actively calling the destructor, the program will eventually call the destructor again

35. The definition of a friend function must be outside the class (×)

//The definition of friend function can be inside or outside the class

36. When the definition of a static member function is outside the class, it is necessary to add the static keyword (×)

37. The function defined in the class is an inline function (√)

//There are two ways to realize the inline function in the class, one is to define it in the class; the other is to define it outside the class, and add the incline keyword before the function definition. Note that the function definition of the second method needs to be placed in the header file

38. When defining a variable of reference type, it must be initialized (√)

39. When calling the copy constructor of a derived class, the constructor of its base class will not be called (×)

40. In the exception handling mechanism, the variable of throw must be caught (×)

 

 

 

Guess you like

Origin blog.csdn.net/m0_63947712/article/details/128321829