nullptr Questions

5

Solved

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() { st...
Forficate asked 12/2, 2015 at 16:34

1

Solved

Hello? I'm studying Doubly Linked List Anyway, when I used to put data on node, there were C6011 error [:Dereferencing Null Pointer 'NewNode'] So I refered https://learn.microsoft.com/ko-kr/visua...
Bartholomew asked 29/9, 2019 at 5:14

2

I want to loop through an array of pointers to an abstract class to find an "empty" slot, that is to check whether an element points to an object of a derived class or not. My approach is to create...
Euphemie asked 23/9, 2019 at 1:41

3

Solved

As far as I'm aware nullptr is a part of the core language. Quoting C++11: (18.2/9) nullptr_t is defined as follows: namespace std { typedef decltype(nullptr) nullptr_t; } and is defined ...
Mushro asked 23/8, 2019 at 14:42

2

Quoting C++11: (18.2/9) nullptr_t is defined as follows: namespace std { typedef decltype(nullptr) nullptr_t; } The type for which nullptr_t is a synonym has the characteristics described ...
Yost asked 21/8, 2019 at 13:50

3

Solved

When used as a boolean expression or transformed into a boolean either explicitly or implicitly, is nullptr consistently false? Is this implementation defined or specified in the standard? I wrote...
Hortensiahorter asked 16/8, 2019 at 15:19

2

Solved

The CppReference page for make_shared says (same with make_unique) May throw std::bad_alloc or any exception thrown by the constructor of T. If an exception is thrown, the functions have no ef...
Mats asked 23/7, 2019 at 7:18

2

Solved

Is this code fragment valid? : unique_ptr<A> p(new A()); p = nullptr; That is, can I assign nullptr to a unique_ptr ? or it will fail? I tried this with the g++ compiler and it worked, b...
Maturity asked 25/2, 2013 at 15:51

1

Solved

I am writing a wrapper for SDL_Texture* raw pointer which returns a unique_ptr. using TexturePtr = std::unique_ptr<SDL_Texture, decltype(&SDL_DestroyTexture)>; TexturePtr loadTexture(SD...
Petrel asked 9/5, 2019 at 17:36

2

Solved

To my knowledge a reference cannot be null, but when I run code like this: #include <iostream> #include <string> void test(int i, const std::string& s = nullptr) { std::cout <...
Malapropism asked 6/5, 2019 at 8:22

2

Solved

I have a following snippet of code that assigned nullptr to bool type. #include <iostream> int main() { bool b = nullptr; std::cout << b; } In clang 3.8.0 working fine. it's give ...
Beefcake asked 18/10, 2017 at 17:20

4

Solved

I have a template like: template <class A, class B> void func(A* a, B* b){ ... } In some cases it happens that parameter B* b is not needed and therefore, I try to use a nullptr: MyA a; ...
Pagano asked 7/6, 2015 at 18:39

3

Solved

This definition works: const auto &b{nullptr}; while this fails: auto *b{nullptr}; I have tried to compile this in Visual C++, GCC, and Clang. They all complain "cannot deduce type". In ...
Kamilahkamillah asked 11/9, 2018 at 11:9

4

Solved

I have some overloaed methods which take some different pointer types. Now I want to call one specific method with nullptr as a parameter. I know that I could cast the nullptr to the specific typ...
Flipflop asked 28/8, 2018 at 10:55

1

Solved

I was playing with SFINAE and found behavior I cannot explain. This compiles fine: template<typename Integer, std::enable_if_t<std::is_integral<Integer>::value>* = nullptr> voi...
Corella asked 8/6, 2018 at 17:28

4

Solved

According to the draft of the standard N4713 (7.11/1): A null pointer constant is an integer literal (5.13.2) with value zero or a prvalue of type std::nullptr_t. and 21.2.3/2: The macro NU...
Oftentimes asked 21/2, 2018 at 10:50

5

Solved

In my early days with C++, I seem to recall you could call a member function with a NULL pointer, and check for that in the member function: class Thing {public: void x();} void Thing::x() { if (...
Cammycamomile asked 2/1, 2018 at 20:20

2

Solved

When I am reading some example code of Qt, I usually see they initialize a pointer to nullptr, for example: QPushButton *startButton = nullptr; I have some very basic idea of nullptr, but never ...
Primer asked 25/12, 2017 at 13:27

2

Solved

currently I am reading "A tour of C++" by Byarne Stroustrup. The thing that matters: on "pointers, arrays and references" he gave an example about using nullptr like this: int count_x(char* p, cha...
Vigue asked 16/12, 2017 at 12:0

2

Solved

C++03 Standard say's: 5.3.5 Delete [...] In either alternative, if the value of the operand of delete is the null pointer the operation has no effect.[...] char *p = nullptr; delete p; //no effec...
Nordine asked 17/11, 2017 at 16:12

1

Solved

And if so, why does the following code give me the warning note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined...

4

Solved

I have a question about C++11 best practices. When clearing a shared_ptr, should I use the reset() function with no parameter, or should I set the shared_ptr to nullptr? For example: std::shared_p...
Phrasing asked 22/4, 2013 at 16:3

1

I learned about std::nullptr_t that is the type of the null pointer literal, nullptr. Then I made small program : #include <iostream> int main() { std::nullptr_t n1; std::cout<<n...
Albano asked 16/9, 2017 at 17:39

5

Solved

I have three LPCWSTR string variables called A, B, C. I am assigning them from another function which can sometimes return nullptr if something goes wrong. like this: A = MyFunc(); B = MyFunc(); ...
Shirleyshirlie asked 4/8, 2017 at 4:18

2

Solved

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 w...
Pederasty asked 13/6, 2017 at 9:31

© 2022 - 2025 — McMap. All rights reserved.