scr888 login apk:scr888,login,apk,锘,This,articl:锘?p> This article will explain the rest of the custom types and explain their semantics. Permissions The provisioning of member functions has enabled the semantics of custom types to be promoted from resources to functional resources. What

scr888 login apk

锘?p> This article will explain the rest of the custom types and explain their semantics.

Permissions The provisioning of member functions has enabled the semantics of custom types to be promoted from resources to functional resources.

What is a functional resource? For example, to map the radio to a number, the mapping operation needs to adjust the frequency of the radio to receive different stations; adjust the volume of the radio; turn the radio on and off to prevent power loss.

To this end, the radio should be mapped to a structure, similar to the following: structRadiogram { doubleFrequency; / * frequency * / voidTurnFreq (doublevalue) ; / / change frequency floatVolume; / * volume * / voidTurnVolume (floatvalue); / / change the volume floatPower ;/*Power*/voidTurnOnOff(boolbOn);//Switch boolbPowerOn;// Whether it is turned on}; The above Radiogram::Frequency, Radiogram::Volume and Radiogram::Power are defined as members of the structure Radiogram, so their semantics They are the frequency of a radio, the volume of a radio, and the power of a radio.

The semantics of the remaining three member functions are also the frequency of changing a radio, changing the volume of a radio, and turning the radio on or off.

Note that 'some' on this side means that which radio is not known, only when the member operator combines a specific radio on the left and combines them to know which radio, which is why they are called Make the offset type. This will be explained in detail in the next article. Note the question: Why do you want to map the three operations just to the member functions of the structure Radiogram? Because the radio has such a function? So for choosing watermelon, cutting watermelon and eating watermelon, is it necessary to define a structure, and then give it three member functions of selection, cutting, and eating? ? Not ridiculous? The former three operations are for the member variables of the structure, while the latter is for the structure itself. Then change to fast food, fast food hamburgers, fast food fries and fast food cola. If the two eating and one drinking operations here become a member function of the fast food, is it a function of fast food? ! This is actually a question of programming thinking, and here is actually the so-called object-oriented programming idea. Although it is a very good idea, it is not necessarily suitable. The next part will be discussed in detail. The reason why we call the radio change is the function, because in practice we can't directly change the frequency of the radio. We must change the receiving frequency by rotating the knob of the channel. Similarly, adjust the volume by adjusting the volume knob. The power reduction caused by the power-on is not directly caused by us, but is caused by indirect listening to the radio. Therefore, the above member variables such as Radiogram::Power, Radiotogram::Frequency have a special feature--the outside world, things other than this radio cannot change them. To this end, C++ provides a syntax to implement this semantics. In the type delimiter, give this format: Permissions:. The permissions here are one of public, protected, and private, called public, protected, and private, as follows: classRadiogram { protected:doublem_Frequency;floatm_Volume;floatm_Power; private:boolm_bPowerOn; public:voidTurnFreq(double);voidTurnVolume( Float);voidTurnOnOff (bool); }; It can be found that it has the same definition format as the previous label, but it is not a statement modifier, that is, structABC{private:}; There is no need to follow the statement in private: because it is not a statement modifier. From it to the next such grammar, all the declarations and definitions between the member variables or member functions have the semantics it represents. For example, the above-mentioned Radiograph, where Radiogram::m_Frequency, Radiogram::m_Volume, and Radiotogram::m_Power are protected member variables, Radiogram::m_bPowerOn is a private member variable, and the remaining three member functions are public. Member function. Note that the above syntax is repeatable, such as: structABC{public:public:longa;private:floatb;public:chard;};. What do you mean? Very simple, the public members can access the outside world, the protected members cannot access the outside world, and the private members and sub-classes cannot access them. About the subclass description. Look at the public first. For the above. The following error will be reported: Radiograma;_Frequency=;_Power=;_bPowerOn=true; Because the above three operations on a use the protection or private member of a, the compiler will report an error because the two members are outside the access. And (10); there is no problem, because the member function Radiogram::TurnFreq is a public member, the outside world can access. So what is the outside world? For a custom type, everything outside the body of the function of the member function of this custom type can be called the outside world. Therefore, for the above Radiogram, only the function body of its three member functions can access its member variables. The code below will have no problems. voidRadiogram::TurnFreq(doublevalue){m_Frequency+=value;} Since m_Frequency is used in the body of the Radiogram::TurnFreq function, it does not belong to the outside world. Why is this so? The semantics of the performance at the beginning. First, defining a member as public or private has no effect on the resulting code. Then, what I said before is to adjust the receiving frequency by adjusting the capacity of the harmonic capacitor inside the radio. The capacity of this capacitor must be achieved by means of components. After the receiving frequency is mapped to a number, since it is a number, then The CPU can be modified. If _Frequency+=10 is directly modified, the meaning of the code is: The person who executes this method increases the receiving frequency of the radio by 10KHz, which is contrary to our objective world and does not match the previous semantics. So providing it as a grammar, reviewed by the compiler, allows us to write code that more closely matches the semantics of the world we live in. It should be noted that unionABC{longa;private:shortb;}; There is no modification before ABC::a here, is it public or protected? I believe that from the many examples mentioned above, it should be public, which is why I have used struct and union to define custom types before, otherwise the previous examples will report an error. The first part said that there is only a small difference between structure and class, that is, when the member is not modified, for the class, that member will be private instead of public, that is, the following will be wrong. classABC{longa;private:shortb;};ABCa;=13; ABC::a is considered private because of the previous class. From this point, it can be seen that the structure is used to map resources (resources that can be used directly), while classes are used to map resources with functions. The semantic differences between the two will be discussed in detail in the next section. Construction and Destruction With the above mentioned things, it is clear that there are the following questions: structABC{private:longa,b;};ABCa={10,20}; Is the above initialization assignment variable a correct? Of course, it is wrong, otherwise it is a loophole in grammar (the outside world can modify the members that cannot be modified). But sometimes it is necessary to initialize to ensure some logical relationships. For this reason, C++ proposes the concept of construction and destruction, which corresponds to initialization and sweeping work respectively. Before we understand this, let's first look at what is called Instance. An instance is an abstract concept that represents an objective existence that is closely related to the concept of the 'world' that will be introduced in the next article. For example: 'This is a table' and 'this table', the former 'table' is a kind, and the latter 'table' is an example. There are 10 sheep here, so there are 10 examples of sheep, and sheep is just a type. It is possible to simply consider an instance as an object of an objective world. Humans classify various objects for convenience. Therefore, the description given to the television does not give an example of a television set, and taking out a television set is giving An example of a television set. Similarly, the code of the program is written with little meaning, and only when it is executed, we call an instance of that program running. If the operating system is required to execute it after it has not been executed, then for the multitasking operating system, it can be said that two instances of that program are being executed. If two Word files are viewed at the same time, there are two. An instance of the Word program is running. In C++, only numbers can be manipulated, and a number is an instance (this can be seen in the description of the next section). More generally, the address of the memory that identifies the record number is an instance, also called a variable. For an example, the corresponding type is the kind of object mentioned above. For example: longa, *pA=a, ra=a;, here are two instances, one is an instance of long, and the other is an instance of long* (note that since ra is long, no instance is generated, but ra is still An example). Similarly, for a custom type, such as: Radiogramab, c[3];, it is said to generate four instances of the Radiogram. For an instance of a custom type, when it is generated, the corresponding constructor is called; when it is destroyed, the corresponding destructor is called. Who is calling? The compiler is responsible for helping us write the necessary code to implement the corresponding construct and destruction calls. The prototype of the constructor (that is, the type corresponding to the function name, such as floatAB(double, char); the prototype is float(double, char)). The format is: directly the type name of the custom type as the function name, no return value type The parameters are arbitrary. For the destructor, the name is preceded by the symbol '~', and there is no return value type. There must be no parameters. As follows: structABC{ABC();ABC(long,long); ~ABC();boolDo(long); longa,count;float*pF;}; ABC::ABC(){a=1;count=0; pF=0;} ABC::ABC(longtem1,longtem2) {a=tem1;count=tem2;pF=newfloat[count];} ABC::~ABC(){delete[]pF;} boolABC::Do( Longcou) { float*p=newfloat[cou]; if(!p) returnfalse; delete[]pF; pF=p; count=cou; returntrue; } externABCg_ABC; voidmain(){ABCa,r=a;(10) {ABCb(10,30);} ABC*p=newABC[10]; delete[]p;} ABCg_a(10,34),g_p=newABC[5]; The above structure ABC defines two constructors (Note that there are two overloaded functions), the names are all ABC::ABC (actually the compiler will convert to a different symbol for connection). A destructor is also defined (note that only one can be defined because it must have no arguments and cannot be overloaded), the name is ABC::~ABC.

Copyright Notice:Original article of this site, in2018/07/20 scr888 login apk,由 Publish。

Please indicate:scr888 login apk:

scr888 login apk This article will explain the rest