Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use nullptr and NULL in C++

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "how to use nullptr and NULL in C++". Xiaobian shows you the operation process through actual cases. The operation method is simple and fast and practical. I hope this article "how to use nullptr and NULL in C++" can help you solve the problem.

1. Why does nullptr appear?

Purpose: nullptr appears primarily to replace NULL.

So why replace NULL?

There are two ways to define NULL, some compilers define NULL as 0, and some compilers define NULL as (void*)0).

What is the difference between these two definitions for c++?

Implicit conversions of ( void* ) to other types are not allowed in c++, and in the case where some compilers define NULL as ((void*)0), NULL becomes defined as 0 when you define variables to assign NULL.

In addition, this problem can also confuse the overloaded nature of c++.

Next, code demonstration

2. code demonstrates

Here is the MyClass class, which has two overloaded functions printf

#include using namespace std;class MyClass{public: MyClass() {} ~MyClass() {}public: void printf(char *) /* overloaded function */ { cout

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report