static constructors and non-static constructors .. it is summarized in two aspects: the first is relative to the process-oriented, that is, the class is not involved in this aspect, and the second is relative to the object-oriented, it mainly describes the role of static in the class. --------------------------------------------------------- I am the delimiter o
value is 1.
To analyze this kind of problem, just remember three o ' line.
First code execution sequence, the code before the first execution;
The second static member initialization statement is executed before the static constructor;
The third static member initia
Preface
In the past, I was always reminded that I should try to use less static variables and data loss during programming. Today I am free and can't help but be curious about static variables, let me share with you the story of the static family.Static class definition
An important difference between static and non-
modify the configuration file on the server. In most cases, we need to create a. htaccess file under the root directory of the website.
The Code is as follows:
RewriteEngine on // start the rewrite EngineRewriteRule ^/index ([0-9] * pai.html $/index. php? Id = $1 // "([0-9] *)" indicates that the range (. *) indicates all, the same below.RewriteRule ^/index ([0-9] *)/$/index. php? Id = $1 [R] // virtual directory
3. m
static variables and static functions in C.(1) The static variables in C are in the global store, which differs from the automatic variables stored in the stack. The key difference between the two is the difference in scope. The scope of an automatic variable is in the funct
static member variables of a class2#include 3 using namespacestd;4 5 classpoint{6 Public:7 Point ()8 {9m_npointcount++;Ten } One~Point () A { -m_npointcount++; - } the Static voidoutput () - { -cout "m_npointcount="Endl; - } + Private: - Static intM_npointcount; + }; A at voidMain () - { - Point pt; - pt.output (); -} Link E
the uniqueness of objects of this type. In fact, the implementation is very simple. Here is a simple example.
Public class mysingleton{Private Static readonly mysingleton _ theoneandonly;Static mysingleton (){_ Theoneandonly = new mysingleton ();}Public static mysingleton theonly{Get {return _ theoneandonly ;}}/// /// Private constructor to avoid object
C # static classes and static class members are used to create data and functions that can be accessed without creating an instance of the class. Static class members can be used to detach data and behavior that are independent of any object identity: No matter what changes the object has, the data and functions do not
Differences between global variables, local variables, static global variables, and static local variables
C ++ variables have different scopes based on different lifecycles at defined locations. They can be divided into six categories: global scope, local scope, statement scope, and Class scope, namespace scope and file scope.
From the scope:
Global variab
maintain. (e.g. code at the beginning of the article)Precautions1) in a static member function, you cannot access a non-static member variable or call a non-static member function.Defects in this Crectangle classWhen using the Crectangle class, the copy constructor is sometimes called to generate a temporary hidden Cr
between the two is that the scope of the Non-static global variable is the entire source program, and when a source program consists of multiple source files, non-static Global variables are valid in each source file. A static global variable restricts its scope, that is, it is only valid within the source file that defines the variable, and it cannot be used in
① static members belong to the class, and non-static members belong to instances of the class.
② every instance of creating a class, the city in memory for the non static (dynamic) State members of the new allocation of a piece of storage;
Static members are owned by the class and are common to instances of each class
global variablesDifference:static global variables cannot be used by other files. Thus other files can define variables of the same name without conflicts.Example://Example//File 1#include voidfn ();Static intN//define static global variables (only available in this file)voidMain () {n= -; coutEndl; fn ();}//File 2#include extern intN; (this variable can be referenced in another file)voidfn () {n++; coutEn
: char *name; int age; float score; static int num; // defines num as a static member variable public char *, int , float ); void Say ();}; This code declares a static member variable num, which is used to count the number of students.Static member variables belong to a class and do not be
1. c ++ variables have different scopes based on different lifecycles of the defined positions. The scopes can be divided into six types:
Global scope, local scope, statement scope, Class scope, namespace scope and file scope.
From the scope:
1> global variables have a global scope. Global variables can be defined in only one source file to act on all source files. Of course, other source files that do not contain the definition of a global variable m
variables and methods of the area, and the code area and the constant area is not directly accessible.The second characteristic of 2.static variables and methods memory analysisThe second attribute of the static variables and methods is that static methods cannot directly invoke normal member variable methods and ordi
, but global objects cannot.
The reader can easily see that static members are associated with a class, which clearly reflects the programmer's intent.
C ++ code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Ifndef _ counted_object_h _# DEFINE _ counted_
Static is a common modifier in C ++. It is used to control the storage and visibility of variables. Next I will talk about the reason and role of static modifiers, the essence of the static modifier is comprehensively analyzed. Static: I. Control Storage Methods:
The 1.c++ variable has different scopes according to the different life cycles of the defined positions, and the scope can be divided into 6 types:Global scopes, local scopes, statement scopes, class scopes, namespace scopes, and file scopes.From the scope view:1> Global variables have global scope. A global variable can be used for all source files simply by defining it in one source file. Of course, other source files that do not contain global vari
The 1.c/c++ variable has different scopes according to the different life cycles of the defined positions, and the scope can be divided into 6 types:Global scopes, local scopes, statement scopes, class scopes, namespace scopes, and file scopes.From the scope view:1> Global variables have global scope. A global variable can be used for all source files simply by defining it in one source file. Of course, oth
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.