C + + static member functions
Like a data member, a member function can also be defined as static, and the preceding addition of a function in a class becomes a static member function. Such as
static int volume ();
As with static
In general, if there are N homogeneous objects, each object has its own member variable, and the member variables of the different objects have their own values, which are irrelevant to each other. But sometimes we want to have one or several member
PHP static member variables and non-static member variables, php static. PHP static member variables and non-static member variables. php static data members can be divided into static variables and non-static variables. static Member: the static
Preface:The member variables between objects and objects are independent of each other. To share data, you need to use static members and static methods. As long as you declare static member variables in a class, you can allocate space for static
PHP static member variables and non-static member variables, PHP static
data members can be divided into static variables, non-static variables, two kinds .Static member: A member in a static class joins the static modifier, which is a statically
A static member cannot be assigned in the class body because it is shared by all objects of that class. You assign a value to it in an object, and that member of the other object
will also change. To avoid confusion, it is not necessary to assign a
1. The definition of static member data, as defined by statically typed variables, to add the keyword static before the definition of the member data.
2. Static member data must have a definite value, but because the member data cannot be
When a data member of a class is declared static, the static data member can only be defined once, and is shared by all objects of the same kind. Each object has a copy of every regular data member in the class, but only one instance of the static
Data members can be divided into static variables, non-static variables, two kinds.Static member: A member in a static class joins the static modifier, which is a statically member. You can access this static member directly using the class name +
PHP static member variables and non-static member variables, php static
Data members can be divided into static variables and non-static variables. Static member: A member in a static class is added with a static modifier, which is a static member.
Data members can be divided into static variables, non-static variables, two kinds.Static member: A member in a static class joins the static modifier, which is a statically member. You can access this static member directly using the class name +
C + + class static members and class static member functionsWhen a data member of a class is declared static, the static data member can only be defined once, and is shared by all objects of the same kind. Each object has a copy of every regular
The member variables between the object and the object are independent of each other. To share data, you need to use static members and static methods .
As long as you declare static member variables in a class, you can allocate space for static
C ++ Primer study note _ 22 _ class and data abstraction (8) -- static member variable, static member function, class/object size, _ 22 -- static
I. static
Each static data member is an object associated with the class and is not associated with the
Data members can be divided into static variables, non-static variables. This article mainly describes the PHP static member variables and non-static member variables, the need for friends can refer to the following
Data members can be divided into
In fact, we can intuitively understand that static member functions cannot invoke non-static member variables.Because both static member functions and static member variables are in the category of classes, andThere is always only one copy of the
First, static each static A data member is an object associated with a class and is not associated with an object of that class ! The non-static data member exists in each object of the class type, and the static data member is
Static Statics member functionIn the class. Static in addition to declaring static member variables, it is also possible to declare a statically member function.The normal member function is able to access all member variables. Static member
Static member: the member with the Static keyword added before the definition. As follows:classcrectangle{ Public: Crectangle (); ~Crectangle (); Static voidprinttotal ();Private: intW, H; Static intNtotalarea; Static intNtotalnumber;};
1.virtual and Static functionsIn C + +, static member functions cannot be declared as virtual functions.For example, the following program will fail to compile.
#include
class Test
{public
:
//Compilation error: Static member
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.