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

Check pointer is not null in destructor

I have class with move constructor. After moving, pointer became null. Do I have to check for not_null in destructor before calling delete? class A { int *data; public: A(size_t size) : data(new int[size]) {} A(A &&rhs) : data(rhs.data)…
Peter
  • 435
  • 1
  • 3
  • 11
0
votes
0 answers

Method returns nullptr when using virtual class

So I have three classes class Map that stores objects of class Recty class Map : public GameObject, public InCollisionMap { public: void Setup(); private: Recty *tile[24][32]; }; class InCollisionMap //interface for map { …
No Name
  • 39
  • 1
  • 8
0
votes
0 answers

I initialize char *str1 = nullptr and output to the screen... But when i want output to other variable i receive empty screen.. Why is it happening?

#include #include int main() { const char *str = "Hello world"; char *str1 = nullptr; std::cout << str << std::endl; // when i output to screan i see hello world std::cout << str1 << std::endl; // when i output to scream i…
0
votes
1 answer

Write access violation when initializing pointer

I am getting a write access violation when attempting to dynamically create an array, it seems as like the memory address at which the pointer is stored is invalid. Header: struct FontType { float left; float right; float…
0
votes
1 answer

UE4 set Actor pointer to null without destroying it in the world

I'm trying to figure out if it is possible to reset the pointer of an Actor and simultaneously not make it disappear from the world. Example: 1. auto Item = GetWorld()->SpawnActor<...>(...); 2. ... 3. Item = nullptr;- resetting just the pointer …
Sheim
  • 59
  • 2
  • 11
0
votes
1 answer

C++ Builder nullptr keyword "Undefined"

In C++ Builder (Berlin) the editor's syntax highlighter shows nullptr as a reserved word. But when compiling I get the error: Undefined symbol 'nullptr' nullptr was added to the C++11 standard and as far I know, C++ Builder Berlin supports C++11. I…
Max Kielland
  • 5,627
  • 9
  • 60
  • 95
0
votes
1 answer

Access Violation with HashTable

I was given an assignment to create a hash table that contains 30 buckets (20 primary, and 10 overflow), with each bucket containing 3 slots (each slot containing 2 stings for key and data passed in), a counter integer and a pointer variable that…
0
votes
0 answers

How Can this == nullptr Ever be true Without Invoking Undefined Behavior?

I was recently reading Programming: Principles and Practice Using C++ (2nd Edition), and I came upon this snippet inside a function for inserting into a linked list (Page 619): if (n==nullptr) return this; if (this==nullptr) return n; The first…
Arnav Borborah
  • 11,357
  • 8
  • 43
  • 88
0
votes
4 answers

Validating a pointer to a pointer in C++

I am trying to write a function that receives a pointer, uses it, and then makes it point to a new object. In order to do this, I am using a ptr-to-ptr. This is how I validate the ptr-to-ptr received by my function: void modifyPtr(Obj **…
user3266738
  • 477
  • 2
  • 12
0
votes
3 answers

Setting a struct element address to null in C++ (singly linked list)

I have this struct: struct Node { int num; Node *next; Node(int, Node*); }; inside class Collection. When I try to delete the last element of the list, using this function: void Collection::remove(int num){ Node *target =…
AthScc
  • 83
  • 10
0
votes
1 answer

Atomically exchange pointer with nullptr

How can I do the following operations in single atomic operation? Is that possible? LARGE_INTEGER* ptr; // field void method() { LARGE_INTEGER* local = ptr; ptr = nullptr; } So I want to store pointer from field into local…
M.kazem Akhgary
  • 18,645
  • 8
  • 57
  • 118
0
votes
3 answers

Is it safe to access TArray at an invalid index?

I want to know if the following code would return nullptr reliably without any complications: TArray SomeActors; ASomeActor* SomeActor = SomeActors[0]; return SomeActor;
Shiro
  • 2,610
  • 2
  • 20
  • 36
0
votes
2 answers

How to define our own nullptr in c++98?

Actually I am writing my own version of all library classes, and I don't want to include the STL files into my class file. So, for example, I want to check whether the node is equal to null. If I write something like #define nullptr 0 Then it is…
ajithcpas
  • 51
  • 1
  • 6
0
votes
1 answer

Custom "nullptr", but how to understand the codes?

It's from Wikipedia, if our compiler don't support c++11 , we can implement one by ourselves , just like below: const class nullptr_t { public: template inline operator T*() const { return 0; } template
LaoJiu
  • 69
  • 7
0
votes
1 answer

C++ Directx Error: Access Violation, swapchain was nullptr

I'm trying to learn 3D Drawing with DirectX and i got this Code in a Tutorial, but every time i try and compile it, my compiler gives out a "Access Violation swapchain was nullptr" Error. Thanks in advance // include the basic windows header…
Erik Schulze
  • 119
  • 9