Questions tagged [nullptr]

The C++11 keyword for a null pointer, it can be converted to any pointer type. Also available in C23 through stddef.h. Always use this tag either in combination with the C++ or the C tag.

In C++, nullptr is a null pointer constant of type std::nullptr_t which can be implicitly converted to any pointer type. An integer constant 0 can also be converted to any pointer type but can also be deduced as an integer in other contexts, leading to ambiguities. See What exactly is nullptr?

In C ("C23" ISO 9899:202x), nullptr is similarly a null pointer constant of type nullptr_t found in stddef.h. It can get converted to a void*, bool or a pointer type.

349 questions
0
votes
3 answers

`std::forward_list` walk until iterator is null?

Is it possible to walk a std::forward_list, incrementing an iterator, until said interator is null? The old-fashioned way... In the following example, I create a print() function. #include #include void…
kmiklas
  • 13,085
  • 22
  • 67
  • 103
0
votes
0 answers

Nullptr not declared in scope and I have included many libraries

I am trying to set initializes for my constructor but I am getting an error saying that nullptr and NULL are both not in scope. I have looked around and saw that I needed to add #include cstddef but I am still getting the same error. template
Andres
  • 13
  • 2
0
votes
1 answer

My head pointer appears null though Im clearly assigning it c++

Basically I'm trying to get this function to work, its functionally a linked list but with node named ticket. Getting an error "head is nullptr" even though its outputting that ive assigned head (cout statements were called). Anyways here is my…
mhm.sherpa
  • 89
  • 1
  • 9
0
votes
2 answers

Box2D compiling trouble. nullptr

guys. I am compiling Box2D from the source code, and give some trouble. I ran lash version of premake in Box2D directory, then I switched to /Build/gmake and ran make. Make return me this: ../../Box2D/Dynamics/b2Body.cpp: In member function ‘void…
0
votes
4 answers

Memory error with pointer

I'm trying to place a value for pointer in my own class vector, but receiving the memory error. Can anybody help me, please? class myVector { int * vector; int size; public: myVector() { size = 0; vector = nullptr; …
inside133
  • 9
  • 1
0
votes
2 answers

The g++ compiler doesn't understand nullptr

My code is compiled using the g++ compiler version 4.9.0. I'm using C++11. However, the compiler doesn't understand the nullptr keyword. Here is what I've found out: This is not a typo, because the word nullptr is displayed in bold in the…
user2738748
  • 1,106
  • 2
  • 19
  • 36
0
votes
1 answer

how to #include a third-party native C++ header that uses nullptr in a C++/CLI project

I am trying to write a managed C++ (aka C++/CLI) library that links to a third-party native C++ library. The third-party library's header files contain constructor definitions that use the nullptr keyword. My managed project fails to compile because…
Will Rogers
  • 431
  • 1
  • 5
  • 14
0
votes
0 answers

C++ strtoul and nullptr error Visual C++ 6.0

I tried my code in Visual studio and it doesn't give me an error, but when I tried my code on visual basic 6.0 c++ file (which should be the app required) , it gives me 2 errors This is my code: #include #include #include…
0
votes
0 answers

Using nullptr to call function

Sorry I couldn't think of any better title after I encountered the following piece of code while experimenting. What I don't understand here is how could I call a function of the class using a nullptr in this case. #include #include…
pranavk
  • 1,774
  • 3
  • 17
  • 25
0
votes
1 answer

How to handle Method returning nullptr for shared_ptr in SWIG (C++ to Java)

I need to port an existing C++ library to Java. In the C++ code there is a factory method: std::shared_ptr createRole(std::string name) which will return a nullptr if it was not possible to create the Role. Unfortunately if I try to port…
little_planet
  • 1,005
  • 1
  • 16
  • 35
0
votes
0 answers

C++: Consistent Expression: file_name != nullptr

Debugging in Visual studio leads to this error: "Expression: file_name != nullptr". It claims the error is in line 30 but there seems to be nothing related. Here is line 30 referenced by the error: unsigned int maxCarbon = 0; // Initialise with…
waap47
  • 9
  • 1
0
votes
6 answers

Difference Between NULL and Zero in Comparing

I know a little bit about NULL, but when it comes to comparing I get confused. For Example: int* p; if(p == NULL){ //do stuff } if(p == 0){ //do stuff } In the first comparison "p" compares with what address? Is it looking for the reference point…
gigili
  • 195
  • 1
  • 13
0
votes
2 answers

Declaring a boolean variable as NULL in C++

Can I use null or nullptr as a bool value instead of 0/false? Since declaring a bool as null means that the bool value is actually zero/false and that does not work in my case. I am using zero/false as another possible outcome. I would like to have…
0
votes
3 answers

Does setting a pointer to nullptr affect other pointers pointing to the same address?

Consider the following function which erases a node from a binary search tree if the node has no children: void erase_no_children(node* todel) { //... if (todel->parent->left == todel) //if todel is left child todel->parent->left =…
DeiDei
  • 10,205
  • 6
  • 55
  • 80
0
votes
3 answers

Vector of pointer declaration

Looking at some code my professor gave me and I don't understand what is happening. I am new to programming and completely lost. vector <_Account*>*myvector = nullptr; So I know he made a vector, and I know of an existing class called Account so…
Franner
  • 88
  • 1
  • 5