Static members can also be defined in a class, but static members are public to all objects. Static members are divided into static data members and static member functions.
1. Static data members
The way to define a static data member in a class
Reprinted from 52725595The role of static in the C language is as followsfirst , when modifying a variable, static local variables are executed only once, and the life cycle of the local variable is extended, until the end of the program runs.
Static members in a class include static member functions and static member data in two partsFirst, static data membersThe declaration of a data member in the class body is preceded by the static keyword, which becomes a data member of that class.
Static and non-static members (functions)C + + Primer "4th edition, page 399:access to a global object is sometimes necessary for all objects of a particular class type. However, global variables can break encapsulation: an object needs to support
This article from http://soft.chinabyte.com/database/176/11595176.shtml
1. In C, these storage areas are divided
1. Stack-automatically allocated and released by the compiler
2. Heap-generally released by the programmer. If the programmer does not
Google C ++ programming style guide (1): header file [this article]Google C ++ programming style guide (2): ScopeGoogleC ++ programming style guide (III): c ++ classGoogle C ++ programming style guide (4): Smart pointers and other C ++
1. Why should I add the extern "C" to call the function compiled by the C compiler in the C ++ program "?A: First, extern is a keyword in the C/C ++ language that indicates the range of the function and global variable. This keyword tells the
Note: This article is excerpted from the Internet. For future convenience, this article is dedicated. Supports originality.
I. In c, there are several storage areas1. Stack-automatically allocated and released by the compiler2. Heap-generally
Static class members include static data members and static function members.
I. static data members:
When the static keyword is added before the declaration of the data member in the class body, the data member becomes the static data member
StackThat is, the storage areas for variables allocated by the compiler when needed and automatically cleared when not needed. The variables are usually local variables and function parameters. In a process, the user stack is located at the top of
Five memory partitions
InC ++Medium, memory is divided5Stack, stack, free storage zone, and global/Static and constant storage.
Stack is the storage area for variables that are automatically allocated by the compiler when necessary and clear
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
The member variables of PHP can be initialized at the same time as the declaration, but only with scalar initialization.
For example:
Class A {public $f 1 = ' xxxx ', static public $f 2 = 100;}
If you want to assign a variable to an object, you can
Binding of data membersIn order to be able to bind specific data members correctly, the earlier C + + compiler prescribes the following two behaviors:
All data member must be placed at the beginning of the class declaration;
All inline
Pointer to a class member
In C ++, you can define a pointer to point to class members or member functions, and then use the pointer to refer to class members. This includes the pointer to the property member and the pointer to the member
The role of static in the C language is as followsFirst, when modifying a variable, static local variables are executed only once, and the life cycle of the local variable is extended, until the end of the program runs.Second, when static modifies
Content interception from http://blog.csdn.net/hackbuteer1/article/details/7487694The C + + keyword Static is used in two ways: in process-oriented programming (common variables and functions in C) and in object- oriented programming (classes in C +
//1. A function defined inside a class is implicitly inline. //2. By default, the type of the this pointer is a constant pointer to a very version of the class type. The const member function for a class is declared by placing the const in the
You cannot reuse the static keyword when you define it outside of a class
The static member function does not contain the this pointer (whether it is displayed or implicitly used)
Static members can be accessed through class objects or
Static member: A member in a static class joins the static modifier, which is a statically member. You can access this static member directly by using the class name + static member name, because static members exist in memory, and non-static
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.