- Learning C++ Functional Programming
- Wisnu Anggoro
- 197字
- 2021-07-02 20:51:35
Pointing to a null pointer
Another new feature in modern C++ is a keyword named nullptr that replaces the NULL macro to represent a null pointer. Now, there's no ambiguity in the use of the NULL macro for zero numeric or a null pointer. Let's suppose we have the following two method's signature in our declaration:
void funct(const char *);
void funct(int)
The former function will pass a pointer as the argument and the latter will pass the integer number as its argument. Then, we invoke the funct() method and pass the NULL macro as the parameter, as shown here:
funct(NULL);
What we intend to call is the former function. However, since we pass the NULL parameters, which is basically defined as 0, the latter function will be invoked. In modern C++, we can use the nullptr keyword to ensure that we will pass a null pointer to the argument. The invocation of the funct() method should be as follows:
funct(nullptr);
Now the compiler will invoke the former function since it passes a null pointer to the argument, and this is what we expect. There will be no ambiguity anymore, and it will avoid unnecessary future problems.
- 復雜軟件設計之道:領域驅動設計全面解析與實戰
- Learning PostgreSQL
- PostgreSQL for Data Architects
- SQL學習指南(第3版)
- C#完全自學教程
- Java開發入行真功夫
- Mastering Yii
- PLC編程與調試技術(松下系列)
- Building RESTful Python Web Services
- Extending Puppet(Second Edition)
- C和C++游戲趣味編程
- Azure Serverless Computing Cookbook
- Mastering VMware Horizon 7(Second Edition)
- 跟小樓老師學用Axure RP 9:玩轉產品原型設計
- Python Django Web從入門到項目實戰(視頻版)