- 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.
- Mastering Visual Studio 2017
- Practical Windows Forensics
- Reactive Programming With Java 9
- 精通網絡視頻核心開發技術
- Swift語言實戰精講
- 速學Python:程序設計從入門到進階
- Scala Data Analysis Cookbook
- LabVIEW虛擬儀器程序設計從入門到精通(第二版)
- 軟件項目管理實用教程
- 移動增值應用開發技術導論
- Illustrator CS6設計與應用任務教程
- Swift語言實戰晉級
- Emotional Intelligence for IT Professionals
- 算法秘籍
- MySQL數據庫應用實戰教程(慕課版)