Generic pointers, native pointers and smart pointers, and pointer intelligence
1. Generic pointer
Generic pointers have many meanings.
(1) refers to the void * pointer, which can point to any data type, so it has the meaning of "generic.
(2) refers to a generic data structure with pointers, including generic iterators and smart pointers.
Broadly speaking, an iterator is an opaque pointer that can traverse access operations. Generally, an iterator refers to a narrow iterator, that is, an instance of classes implemented based on generic iterator_traits in C ++-based STL.
In general, generic pointers and iterators are two different concepts, and the intersection of them is the iterator class.
2. The native pointer is a normal pointer. Compared with it, it acts like a pointer, but it is not a pointer.
"Native" refers to "the simplest and most basic one ". Because many things are abstracted and theoretically made, "the simplest and most basic pointer of the past" is just one of the manifestations of abstract concepts (such as iterator.
3. smart pointer is a concept in C ++: Since C ++ does not have an automatic memory reclaim mechanism, programmers have to handle memory-related problems each time, however, using smart pointers can effectively alleviate such problems.
The introduction of smart pointers can prevent suspension of pointers.
Generally, a pointer is encapsulated into a smart pointer class. In addition, a counter is encapsulated in this class. operations such as copying a pointer will increase the value of this counter by 1, the delete operation on the pointer is reduced by 1. When the value is 0, the pointer is NULL.
How can we distinguish between generic pointers, native pointers and smart pointers?
1. Generic pointer
Generic pointers have many meanings.
(1) refers to the void * pointer, which can point to any data type, so it has the meaning of "generic.
(2) refers to a generic data structure with pointers, including generic iterators and smart pointers.
Broadly speaking, an iterator is an opaque pointer that can traverse access operations. Generally, an iterator refers to a narrow iterator, that is, an instance of classes implemented based on generic iterator_traits in C ++-based STL.
In general, generic pointers and iterators are two different concepts, and the intersection of them is the iterator class.
2. The native pointer is a normal pointer. Compared with it, it acts like a pointer, but it is not a pointer.
"Native" refers to "the simplest and most basic one ". Because many things are abstracted and theoretically made, "the simplest and most basic pointer of the past" is just one of the manifestations of abstract concepts (such as iterator.
3. smart pointer is a concept in C ++: Since C ++ does not have an automatic memory reclaim mechanism, programmers have to handle memory-related problems each time, however, using smart pointers can effectively alleviate such problems.
The introduction of smart pointers can prevent suspension of pointers.
Generally, a pointer is encapsulated into a smart pointer class. In addition, a counter is encapsulated in this class. operations such as copying a pointer will increase the value of this counter by 1, the delete operation on the pointer is reduced by 1. When the value is 0, the pointer is NULL.
In C language, since generic pointers exist, why do we need to differentiate common pointers in data classes?
Void * pointer cannot be unreferenced...
The normal pointer type carries one of the methods used to access that object ..
If there is no type, the object cannot be accessed ..