References: http://blog.chinaunix.net/uid-14114479-id-3035143.html
Http://www.cnblogs.com/lzjsky/archive/2011/01/24/1943199.html
Data members can be divided into static variables and non-static variables. static member: A member in a static
C ++ static member and static member
URL: http://www.cnblogs.com/archimedes/p/cpp-static2.htmlStatic Data Member
Definition:
Data member declared with the keyword static
class Box{public: int volume() const;private: int iwitch; int length;
Static member functions cannot access non-static member functions.
The static member function does not include the this pointer.
The non-static member function implies the this pointer. To call a non-static member function, this pointer is
1. Review of member variables(1) Access to public member variables by object name(2) The member variables of each object are exclusive(3) member variables cannot be shared between objects2. static member variables(1) Static member variables in C +
Introduction to static summary staticStatic is a very common modifier in C + +, which is used to control how variables are stored and visible.A variable defined inside a function, when the program executes to its definition, the compiler allocates
In C ++, when a static member function accesses a non-static member variable, first look at a classclass
{
Public:
Static functiona ()
{
Menber = 1;
}
PRIVATE:
Int menber;
}
An error occurred while compiling the above Code. The reason is simple.
The declared functions in the class have three meanings compared to the class:1. This pointer is available2. The function is in the Action Area of the class.3. Private part of the category
4. can be inherited
Non-static member functions have
Before proceeding to the subject, I think we should first propose two self-defined terms: class-level members and object-level members ). I don't know if such a term already exists in the C ++ field, but I think these two terms can help us
Static member functions in C + + are part of the entire class, not an object, so you do not need to create objects to access1. Function definitions that appear outside the class body cannot specify the keyword static;2. Static members can access
Code:1#include 2#include string>3#include 4 5 using namespacestd;6 7 classa{8 Public:9 Static intA;Ten //static int a = 0;//compilation does not pass and cannot be initialized within a class One intb; A Static
Before I turn to the point, I think we should first put forward two of my own custom terms: class level members and object level members. I don't know if there is such a term in the C + + domain, but I think these two terms can help us understand
In multi-threaded programs, whether we use afxbeginthread, createthread, and _ beginthread to construct a thread function, because the thread function can only be a global function or a static function, the static function is used as an example
Static data members
• Use the keyword static declaration
• When declaring a class's data member as static, no matter how many classes of objects are created, the static member has only one copy
• Shared in all objects of a class with static
The class bytecode file is loaded into memory by the JVM virtual machine, followed by
Connection
Verification: Byte code verification
Prepare: Allocates memory for static variables and assigns default values for variable
A static member function is a member function of a class. It does not belong to any object applied for by the class, but a function shared by all the members of the class.
Like static data members, static member functions are part of a class, not
When a function is not part of a specific instance and belongs to the entire class, then this function is best written as a static member function, so that it can be called directly with the class nameClass::func ()For general member functions when
Copy Code code as follows:
Class A
{
Public
Static Functiona ()
{
Menber = 1;
}
Privateint menber;}
There was an error compiling the above code. The reason is simple, as you all know, static member functions cannot
If you write a single example of C + +:classSingleton {Private: StaticSingleton *Singleton;Private: Singleton () {} Public: StaticSingleton *getinstance () {if(Singleton = =NULL) {Singleton::singleton=NewSingleton (); } returnSingleton;
The reason why static member functions in C ++ cannot be modified using static:
The fifth meaning of static in C ++: use static to modify class member functions that do not access non-static data members. This means that a static member function can
Introduction to C ++ new and delete keywords, static member attributes and functions, usage of this pointer, and delete keywordsNew and delete keywords
The new and delete keywords are provided in C ++. new is used to open up the memory, delete is
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.