C++ Fundamentals 2

2. In the C language, struct has its own meaning. Although it is extended into a class in C++, it generally follows the usage in C.

3. C++ generally uses class as a keyword declaration for a class

4. Inheritance is a way of code reuse in C++. Through inheritance, the code in the parent class can be used in the subclass

5. The subclass can completely inherit all the variables and functions in the parent class, and can be replaced by the subclass where the parent class can be used

6. A subclass is conceptually a special kind of parent class

7. The relationship between the class and the divided class is called: inheritance, which has all the attributes of the original class, and the relationship between the classes is called: combination.

8. Attributes are mainly used to describe the static characteristics of classes, and behaviors are mainly used to describe the dynamic characteristics of classes

9. Use variables to represent properties and functions to represent behavior

10. Classes are usually divided into two parts:

(1) Implementation details of the class:

(2) How the class is used;

(3) When using a class, you don't need to care about its implementation details

(4) When creating a class, you only need to consider its internal implementation details

11. Basic Concepts of Encapsulation

.Not every property of a class is exposed to the public

.And some class properties are exposed to the outside world

. Therefore, the exposure level of properties and behavior needs to be defined in the class's notation

12. Encapsulation of classes in C++:

.member variables (variables used to represent class attributes in C++)

.member functions ( variables used in C++ to represent class behavior )

.In C++ you can define access levels for member variables and member functions

.public--The outside of the class can be freely accessed

 .protected--the class itself and subclasses can access

 .private - accessible within the class itself

13. The scope of class members is only inside the class and cannot be directly accessed from outside

.member functions can directly access member variables and call other member functions

14. The outside of the class can access public members through class variables

.The scope of a class member has nothing to do with the access level

All members of a class defined with struct in C++ default to punlic

15. Class is represented by class in C++, and struct is represented by struct in C language

The usage of class and struct is exactly the same. In C++, class is private by default, and struct is public by default in C.

Construction and Destruction

16. A class in C++ can define a special member function with the same name as the class

17. This member function with the same name as the class is called a constructor

18. Constructors can have parameters when they are defined, but do not have any return type declaration

19. The call of the constructor

. Under normal circumstances, the C++ compiler will automatically call the constructor

.In some cases you need to manually call the constructor

20. Overloading of member functions:

.Class member functions can be overloaded like ordinary functions and obey the same overloading rules

21. Two special constructors:

.Constructor with no arguments (default constructor):

.Constructor with const reference (copy constructor):

22. When no constructor is defined in the class, the C++ compiler will automatically provide,

When a constructor is defined, the C++ compiler does not provide a parameterless constructor

23. Member variables cannot be initialized when operating on a class

24. Initialization list is provided in C++ to initialize member variables

Grammar rules:

Constructor::Contructor():m1(v1),m2(v1,v2),m3(v3){}

25. The initialization order of member variables is related to the declaration order, not to the order in the initialization list

The initialization list is executed before the function body of the constructor

26. The const member in the class will definitely be allocated space

27. The const member variable in the class is just a read-only variable (the compiler cannot directly get the initial value of the const member variable, so it cannot enter the symbol table to become a real constant)

28. Initialization is different from assignment:

Initialization is to initialize the object being created with an existing object or value (the object being initialized is being created)

Assignment is to set the value of an existing object with an existing object or value (the object being assigned already exists)

29. Generally speaking, all destroyed objects need to be cleaned up

30. Scheme:

. Provide a public destroy function for each class

.The destroy function is called as soon as the object is no longer needed to clean up

31. The resource applied in the constructor needs to be released before the object is destroyed

32. A class in C++ can define a special member function to clean up the object

33. This special member function is called a destructor: define ~classname()

.destructor has no parameters nor any return type declaration

.The destructor is automatically called when the object is destroyed

34. Static members of a class

.Can define static member variables and static member functions in C++

.Static members belong to the entire class and do not need to depend on any objects

. You can directly access public static members through the class name

. can access public static members by object name

.Static member functions can directly access static member variables

35. The definition of static member variables (static) members and functions are both

36. Member variables and member functions in C++ class objects are stored separately. Member variables are stored in the object, static is stored in the global data area, and member functions are stored in the code segment. In the computer, the program consists of a data segment and a code segment. of.

37. this pointer points to the current object

operator overloading

38. The <name.h> header file in the C library corresponds to the <cname> in C++

39.cout represents the object of the screen, cin represents the object of the keyboard, and the endl identifier represents the line feed operation.

40. Operator overloading provides different semantics for operators

41. The function expansion operator can be used in C++ through the operator keyword

. The essence of operator is to implement operator overloading through function overloading

42. The private declaration makes the members of the class inaccessible to the outside world

But through the friend keyword can be exception open permissions, ostream output stream

43. Operators overloaded with member functions

. has one less argument than the global operator overloaded function, the left operand

.No need to use friend keyword

44. Operator overloading:

.Use global function for overloading when the class of the left operand cannot be modified

The .=, [], and -> operators can only be overloaded through member functions

45. && and || cannot implement the short-circuit rule .


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325950923&siteId=291194637