All Questions

442
votes
9answers
253489 views

What exactly is nullptr?

We now have C++11 with many new features. An interesting and confusing one (at least for me) is the new nullptr. Well, no need anymore for the nasty macro NULL. int* x = nullptr; myclass* obj = null...
132
votes
7answers
43593 views

What are the advantages of using nullptr?

This piece of code conceptually does the same thing for the three pointers (safe pointer initialization): int* p1 = nullptr; int* p2 = NULL; int* p3 = 0; And so, what are the advantages of assignin...
90
votes
4answers
83650 views

NULL vs nullptr (Why was it replaced?)

I know that in C++ 0x or NULL was replaced by nullptr in pointer-based applications. I'm just curious of the exact reason why they made this replacement? In what scenario is using nullptr over NULL ...
46
votes
5answers
17476 views

Can nullptr be emulated in gcc?

I saw that nullptr was implemented in Visual Studio 2010. I like the concept and want to start using it as soon as possible; however GCC does not support it yet. My code needs to run on both (but does...
16
votes
4answers
2204 views

c++ access static members using null pointer

Recently tried the following program and it compiles, runs fine and produces expected output instead of any runtime error. #include <iostream> class demo { public: static void fun()...
19
votes
3answers
750 views

Are these null pointers, or are they pointers to address 0?

If I write int zero = 0; void *p1 = (void *)0; void *p2 = (void *)(int)0; void *p3 = (void *)(0 /*no-op, but does it affect the next zero?*/, 0); void *p4 = (void *)zero; // For reference, this ...
20
votes
4answers
31739 views

What header file needs to be included for using nullptr in g++?

I am using g++ 4.4.1 and want to use nullptr, but I am not being able to find which header file is required to be included. It does not seem to be keyword either, because my attempt to use it is rejec...
7
votes
2answers
3450 views

"Backporting" nullptr to C++-pre-C++0x programs

More or less what the title suggests. While I'm not yet using C++0x I'd like to be prepared for when it happens, and I'd also like to reduce the amount of code I have to rewrite to use some of its fac...
5
votes
2answers
4252 views

In c++11, does dynamic_cast return nullptr or 0?

I want to check the result of dynamic_cast. In c++11 (or c++0x, for compilers that support nullptr), should I compare against nullptr or 0? Does it matter, and if so, why? Is the result compiler-de...
6
votes
1answers
1269 views

gcc nullptr issue

I am porting existing code to compile under gcc 4.7.2 and have run into a strange issue with nullptr. I have managed to boil it down to a simple test case: #include <stdio.h> const char* g_mar...

Previous Next