In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you what is the basic concept of C++ void. It is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Many concepts in C++ programming language are worth learning and accumulating experience to help us get more help in programming. For example, C++ void introduced to you today is a relatively important part of ige. Many beginners do not understand C++ void and void pointer types, so there are some errors in their use. This article will explain the profound meaning of the void keyword and describe in detail the methods and techniques for using void and void pointer types.
Void literally means "untyped", void * means "untyped pointer", and void * can point to any type of data.
Void almost only "comments" and restricts the role of the program, because no one has ever defined a void variable, let's try to define:
Void a
This line of statement will cause an error when compiling, prompting "illegal use of type 'void'". However, even if the compilation of void a does not go wrong, it does not make any practical sense.
Sharing of common application skills of C++ clipboard
C++ Doxygen implements function sharing
Detailed explanation of C++ sprintf format solution
The difference between C++ function object and function pointer
Interpretation of the implementation Code of C++ one-way linked list
The real role of C++ void is:
(1) restrictions on the return of a function
(2) the limitation of function parameters.
We will elaborate on the above two points in the third section.
As we all know, if pointers p1 and p2 are of the same type, we can assign values to each other directly between p1 and p2; if p1 and p2 point to different data types, you must use a cast operator to convert the pointer type on the right of the assignment operator to the type of pointer on the left.
For example:
Float * p1; int * p2; p1 = p2
The statement p1 = p2 will cause a compilation error, prompting "'=': cannot convert from 'int *' to 'float *", which must be changed to:
P1 = (float *) p2
Unlike void *, pointers of any type can be assigned directly to it without casting:
Void * p1; int * p2; p1 = p2
However, this does not mean that void * can also be assigned to pointers of other types without casting. Because "untyped" can contain "typed", while "typed" cannot contain "untyped". The reason is very simple. We can say that "men and women are both human beings", but we cannot say that "people are men" or "people are women". There was an error compiling the following statement:
Void * p1; int * p2; p2 = p1
Prompt "'=': cannot convert from 'void *' to 'int *'".
The above is the basic concept of C++ void. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.