C + + Fundamentals 2

Source: Internet
Author: User

2. The struct has its own meaning in C, and although it is extended to a class in C + +, the general situation follows the usage in C

3.c++ general use class to make a keyword declaration

4. Inheritance is the way code is reused in C + +, and through inheritance, code in the parent class can be used in subclasses

5. Subclasses can completely inherit all the variables and functions in the parent class, where they can be used instead of the subclass.

6. Subclasses are conceptually a special kind of parent class

7. the relationship between classes and classes is called inheritance, which has all the properties of the original class, and the relationship between the classes is called: a combination.

8. properties are primarily used to describe the static characteristics of a class, and behavior primarily describes the dynamic nature of the class

9. use a variable to represent a property and use a function to represent the behavior

10. Classes are usually divided into two sections:

(1) Implementation details of the class:

(2) The mode of use of the class;

(3) When you use a class, you do not need to care about its implementation details

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

11. Basic concepts of encapsulation

Not every property of a class is publicly available

The properties of some classes are exposed externally.

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

Encapsulation of classes in 12.c++:

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

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

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

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

. The protected--class itself and subclasses can access

. The private--class itself can be accessed

13. Class members are scoped only inside the class and cannot be accessed directly outside the

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

14. Outside the class you can access public members through class variables

The scope of a class member is not related to the access level

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

In c + +, classes are represented by class, and structs are represented in the C language .

Class and struct are used exactly the same, in C + + class class default is private, in C struct default is public

Construction and destruction

Classes in 16.c++ can define special member functions that are the same as class names

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

The constructor can have parameters when defined, but there is no declaration of any return type

19. Calls to constructors

. In general, the C + + compiler automatically calls constructors

. In some cases, you need to call the constructor manually

20. Overloading of member functions:

The member functions of the. class can be overloaded as well as normal functions and follow the same overloaded rules

21. Two special constructors:

. Constructors without parameters (default constructor):

. constructor with const reference (copy constructor):

22. When no one constructor is defined in the class, the C + + compiler automatically provides

When a constructor is defined, the C + + compiler does not provide an argument-free constructor

At the time of operation on the class, member variables cannot be initialized

The initialization list is provided in 24.c++ to initialize the member variable.

Syntax rules:

Constructor::contructor (): M1 (v1), M2 (v1,v2), M3 (v3) {}

25. The initialization order of member variables is related to the order of declaration, regardless of the order in which they are initialized

The initialization list executes before the function body of the constructor

26. A const member in a class is one that will definitely be allocated space.

27. A const member variable in a class is simply a read-only variable (the compiler cannot directly get the initial value of a const member variable, so it cannot enter the symbol table as a true constant)

28. Initialization differs from assignment:

Initialization is the initial setting of 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 already existing object with an existing object or value (an assigned object already exists)

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

30. Programme:

. Provide a public destroy function for each class

The. Object is no longer required to be cleaned immediately by calling the Destroy function

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

Classes in 32.c++ can define a special member function cleanup object

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

The destructor has no arguments and no declaration of any return type

The destructor is automatically called when the object is destroyed

Static members of the. Class

You can define static member variables and static member functions in C + +

Static members are owned by the entire class and do not need to be dependent on any object

. public static members can be accessed directly through the class name

. public static members can be accessed by object name

Static member functions can access static member variables directly

35. Static member variables are defined (static) members and functions are

The member variables and member functions in the 36.c++ class object are stored separately, the member variables are stored in the object, static is stored in the global data area, the member functions are stored in the code snippet, and the program is composed of data segments and code snippets.

The. Thispointer points to the current object

Operator overloading

38.C Library <name.h> header files correspond to <cname> in C + +

39.cout represents the object of the screen, CIN represents the object of the keyboard, and the Endl identifier represents a line break operation.

40. Operator overloading provides different semantics for operators

Function extension operator can be used in 41.c++ by operator keyword

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

Theprivate declaration makes it impossible for members of the class to be accessed by outsiders

But with the friend keyword can be exceptions to open permissions,ostream output stream

43. Operators overloaded with member functions

. One parameter less than the global operator overload function, which is the left operand

. You do not need to use the Friend keyword

44. Operator Overloading:

When you cannot modify the class of the left operand, use the global function to overload

. =,[], and-operator can only be overloaded by member functions

&& | | The short-circuit rule cannot be implemented .


C + + Fundamentals 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.