In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Type of pointer
Different types of pointers are no different from a memory requirements point of view! That is, the "pointer type" causes the compiler to interpret the contents of memory in a particular address and its size.
1. An integer address pointing to address 1000, on a 32-bit machine, will cover the address space 10001003
2. So, what address space will be covered by a pointer to address 1000 with a type of void*? I don't know, which is why a pointer of type void* can only contain an address and cannot manipulate the object it refers to.
In fact, transformation is a compiler instruction, in most cases, it does not change the real address contained in a pointer, it only affects the interpretation of "the size and content of the indicated memory".
Class ZooAnimal {
Public:
ZooAnimal ()
Virtual~ZooAnimal ()
Virtualvoid rotate ()
Protected:
Intloc
Stringname
}
Class bear:public ZooAnimal
{
Public:
Bear ()
~ Bear ()
Voidrotate ()
Viratul void dance ()
Protected:
Int cell_block
}
But after considering polymorphism? Join Bear to inherit ZooAnimal and Public inheritance
Bear b
ZooAnimal * pz = & b
Bear* pb = & b
Each of them points to the first byte of the Bear object. The difference between them is that the address covered by pb contains the entire Bear object, while the address covered by pz contains only ZooAnimal child objects in the Bear object.
With the exception of members that appear in ZooAnimal, you cannot use pz to directly deal with any member of Bear. The only exception is through the virtual mechanism.
Pz- > cell_block
((Bear*) pz)-> cell_block
/ / after a clear transformation operation, there will be no problem.
Pb- > cell_block
/ / legal because cell_block is a member of Bear
But when we write
Fixed available interface, that is, pz can only call ZooAnimal's Public interface
The access level of the interface (for example, rotate () is a public member of ZooAnimal)
At each execution point, the object type referred to by pz can determine the entity called by rotate (). The encapsulation of type information is not between maintenance and pz, but between maintenance and link. This Link exists between the vptr of the object and the virtual table referred to by vptr, and there is an information of type of info in every virtual table.
Bear b
ZooAnimal za = b; / / this will cause cutting
Za.rotate (); / / call ZooAnimal::rotate ()
Why does rotate () call ZooAnimal entities instead of Bear entities? Why doesn't za's vptr point to Bear's virtual table?
The compiler arbitrates between initialization and assignment (assigning one object to another). The compiler must ensure that if an object contains one or more vptrs, the contents of the vptrs are not initialized or changed by the base class object
Add ZooAnimal- > Bear- > Panda inheritance relationship
ZooAnimal za
ZooAnimal * pza
Bear b
Panda* pp = new Panda
Pza = * b
The so-called type-related memory delegate operation refers to the size that the type is compiled to recognize, for example, using pz- > cell_block above.
The size and content interpretation occurs during compilation, but for polymorphism, it is a function, but the function is not attached to the object. If the function exists in the accessed object and the access level of the function can be reached, it can be implemented during compilation, but during run time, if the function is found to be a virtual function At this time, the first position in the virtual function table is all the information about the type, and you will know what the real type of the object is. We need to distinguish the difference between these two points.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.