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
-1
votes
1 answer

Win32 CreateWindow() error, this is nullptr

I'm creating a child window in another class, so I pass the hWnd and the hInstance of the parent into the function, where I'm creating the child window. My problem now is, that the createWindow() function of the child window hangs up and I get an…
-1
votes
1 answer

c++ overloading subscript dereference where nullptr is allowed

Hi I'm a student developing various abstract data types for learning purposes. I am trying to overload the subscript operator to look up the keys in these ADT's. I cannot avoid the case where my code inserts missing keys. It is intended that when…
clns
  • 1
-1
votes
2 answers

If statement not catching nullptr

I have a program that is supposed to take an unknown number of strings from a user. It supposed to check and see if a string has already been entered so that there will be no duplicates in the dynamic array. The problem is that I can't get the…
Chaospyke
  • 62
  • 9
-1
votes
1 answer

nullptr not declared even with C++11 and C++14 enabled

I just installed CodeLite and the latest version of the TDM-GCC compiler. It supports both C++11 and C++14. However, when I write a program using nullptr it is still telling me that 'nullptr' was not declared in this scope . What else do I have to…
user6365860
-1
votes
1 answer

C++ How to reassign a pointer to an object with this as argument?

I need to make a pointer to an object of a class. However, it is declared as nullptr first. I need to make it point to that class. Here, I declare them as nullptr: #pragma once #include "Window.h" #include "Game.h" #include "Map.h" #include…
OpenGLmaster1992
  • 281
  • 2
  • 5
  • 13
-2
votes
0 answers

C++ shifting a pointer to another class instance | removing/deleting pointer

I'm new to c++ programming and I'm trying to make a chessgame in which I have classes that represent chesspieces on a chessboard. I've made instances of chesstiles on the chessboard that contain instances of chesspieces. If I shift one chessPiece…
Defecter
  • 1
  • 2
-2
votes
1 answer

Segmentation fault when pointing a non-nullptr struct

I'm basically working on a program that allows you to make simple genograms, using C++ in a Linux environment. Here's the entire code I've made for now: genogram.h #include #include #include #include…
-2
votes
1 answer

Array of pointers remaining null despite being directly set

I have a list of 'cell' objects in a 2d array of length [sizeX][sizeY]. These Cell objects contain an array of type *Cell, which should point to each of the given cell's adjacent cells in the format North, East, South, West (Never Eat Soggy…
dlarkr
  • 3
  • 4
-2
votes
1 answer

C++ 11 standards - initialize member variables in header

Is it necessary to initialize member variables with nullptr or Q_NULLPTR in header files? If yes, why is it so required, when I do proper initialize it the ctor initialization list. in MyDialog.h, QDialog* m_Dialog = Q_NULLPTR; and in…
Sayan Bera
  • 135
  • 2
  • 16
-2
votes
1 answer

*pointer was nullptr* error in C programming

I have a serious problame. at the line **c = (int*)malloc(size1 * sizeof(int*)); the compiler gives me this error which I don't really know what it says. Unhandled exception thrown: read access violation. c was nullptr. occurred I don't know what…
-2
votes
1 answer

Implementing a reference counter with a limit of 3 pointers

**Update added main and cat Hello all i am creating a sharedpointer class that has a reference counter. What im trying to do is when i create a new object and give it value i can do so until i reach a cap of 3. If i create anymore objects they will…
m00se
  • 11
  • 4
-2
votes
4 answers

Can't find my memory leak in this simple code

I was 100% positive that I covered all ground in terms of deleting memory from the heap before it was lost, but valgrind seems to disagree. Any help with finding the leak in the following code would be greatly appreciated! I can't seem to figure out…
JayB
  • 397
  • 6
  • 21
-3
votes
1 answer

Why is it invalid to reassign a pointer that was previously assigned nullptr?

I am new to C++ and am following the book "Programming Principles and Practices using C++". I came across something that I could not understand completely. Hopefully someone can help me understand this. Why is this invalid? int* p = nullptr; *p =…
Koel
  • 1
  • 2
-3
votes
3 answers

c++ std::vector "this" was "nullptr"

for some reason I can not use the vector _vec in datacenter.cpp. It says "this" was "nullptr" please help, thanks <3 datacenter.h #pragma once #include #include class datacenter { public: datacenter(); ~datacenter(); …
-4
votes
3 answers

nullptr read access violation while checking in loop

I have this code: while (current->next->data <= temp->data && current->next != nullptr) { current = current->next; } when I run it i get the error: Exception thrown: read access violation. current->next was…
1 2 3
23
24