// This program is used to differentiate the following six pointers: 1. Common pointer 2. Common function pointer 3. pointer to the data member of the class// 4. pointer to the member function of the Class 5. pointer to the static data member of the
C ++ static keywords
C ++ static keywords
Static is a common modifier in C ++. It is used to control the storage and visibility of variables.
Process-oriented static
-Static global variables
Add the keyword static before the global
1. Single Case mode(1) Demand: In architecture design, some classes can have at most one object in the entire system life cycle (Single,instance)(2) Question: How do you define a class so that the class can create at most one object?To control the
Summary of the use of C + + static member variables and static member functions:A. Static member variables:The declaration of a data member in the class body is preceded by the static keyword, which becomes a data member of that class. As with other
Sometimes the implementation of a class, but only need to create an instantiated object to complete the requirements, if there are too many objects not only waste memory space will also make the code data is not so good maintenance, so you will need
1. Static member functions can be stored with normal function pointers, and ordinary member functions must be stored with class function pointersClass a{public:static void Fun () {cout 2. Static member functions can not call non-static member
We will define member functions in the class, and we also want to define member function pointers. Therefore, we need to solve three problems: first, how to define the class function pointer, second assignment, and third use.I define a
The values of static data members are the same for each object. It is a headache for professional programmers to implement static member functions, after reading this article, you will surely be able to solve the problem of static member functions
How does static work?In the interview, it is easy to ask the basic questions, but also the most easily ignored by everyone.member variables of the static modifier classA variable appears in class, such as:Class Example{Public static int A;...};When
One, the dynamic establishment and release of objects1. What is the dynamic creation and release of objectsUsually we create objects that are created by the C + + compiler for us in stack memory, and we cannot manage the lifecycle of them. So we
Object-oriented deep learning after class (detailed explanation of static members of class C ++)
I just applied for a blog today and wrote the essay all afternoon. So I decided to come to the end of c ++ and I will take the exam next week, I don't
Life cycle of an objectCan be divided into static life cycle and dynamic life cycle1. Static life cycleIf the lifetime of an object is the same as the run time of the program, we call it a static Lifetime. Objects declared in the scope of a file
Class Definition details in C ++
Member variables
Each class can have no members or multiple members. The members can be data, functions, or type aliases.
A class can contain several public, private, and protected parts. Members defined in the
First, design Patterns1. Single-case modePurpose: To allow a class to generate only one objectStep: ① the constructor into private② make a static member function object in a class③ limiting conditions in the method Riga //single-case mode
The const -defined constants are freed after the function executes, and static constants defined by the statics are not freed when the function is executed. However, whether they are const or static, the content they define will be known to the
C Language Section1. Analysis of pointersint (*p) [5] and int *p[5]The former is a pointer to an array that contains 5 elements. The latter is an array with a length of 5, and each element in the array points to an integer variable.int *f (int i,
Original address: Http://blog.csdn.net/he3913/archive/2008/09/18/2944737.aspx C + + static member function (cannot be used for const reason +static in C + + ----Self core C + + static in C + + The fifth meaning in the static modifier
Preprocessing command: Exists in the xxx.h file#ifndef// Prevent duplicate inclusions#define// definition#endif// EndPrecompiled directives are not added to the header file, resulting in a duplicate definition of a compile-time error.During the
There are three (specifically two) uses of the static keyword for C language:1. Static local variables: used in the function body interior modification variables, the lifetime of such a variable longer than the function. int foo () {
Static and const are very important concepts in C + + programming, and the examples in this article enumerate the rules and usages of static and const in C + + classes. For reference. The details are as follows:
First, use the code to illustrate.
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.