- 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.
- Unreal Engine Physics Essentials
- Nginx實戰:基于Lua語言的配置、開發與架構詳解
- 深入理解Elasticsearch(原書第3版)
- Asynchronous Android Programming(Second Edition)
- Test-Driven Development with Django
- Mastering React
- Python爬蟲、數據分析與可視化:工具詳解與案例實戰
- Node學習指南(第2版)
- 后臺開發:核心技術與應用實踐
- Hadoop 2.X HDFS源碼剖析
- HTML5+CSS3+jQuery Mobile APP與移動網站設計從入門到精通
- 超好玩的Scratch 3.5少兒編程
- Python第三方庫開發應用實戰
- PostgreSQL Developer's Guide
- Python應用開發技術