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
2 answers

Missing nullptr for undeclared array element

I am trying to make a basic HashMap. I am checking to see if an element exists at an index before inserting it there. When I insert my first element, it says that an element already exists at that position. I have gone through the debugger, and…
Evorlor
  • 7,263
  • 17
  • 70
  • 141
0
votes
1 answer

Unable to load web page using the CefSharp embedded Chromium browser control?

I'm having a rough go of it getting started. First, I tried using the NuGet package(s). When I installed them none of the necessary references to the CefSharp DLLs showed up in my References list. So I added them by hand by searching the…
Robert Oschler
  • 14,153
  • 18
  • 94
  • 227
0
votes
2 answers

Null parameter check C++

I have a function that solves one of 4 kinematic equations. The parameters are floats, and Is there a way to distinguish between a NULL parameter and a parameter with a value of 0. I've read up on the subject and it seems that NULL and 0 are the…
Orange Mushroom
  • 431
  • 4
  • 16
0
votes
1 answer

nullptr not declared in scopt WITH c++11 support

I have installed: gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) As IDE I use either eclipse CDT or Code::Blocks, does not matter which one. I will stick to Code::Blocks for now. If i use a null pointer in my code I get: nullptr was not declared in…
BuddhaWithBigBelly
  • 345
  • 1
  • 6
  • 15
0
votes
4 answers

Does nullptr release the memory of a pointer?

What I'm asking is if a pointer should be deleted even if nullptr has been assigned to it. For example, in the following case: std::string* foo = new std::string ("foo"); foo = nullptr; Is the memory occupied before nullptr released or are we…
0
votes
0 answers

Cocos2d - CCLabelAtlas - asset is nullptr (android)

when I do : auto label = CCLabelAtlas::create(StringUtils::toString(speed).c_str(), "arial_image.bmp"); I get : 09-17 08:37:40.856: D/CCFileUtilsAndroid.cpp(1563): relative path = arial_image.bmp 09-17 08:37:40.856: D/CCFileUtilsAndroid.cpp(1563):…
degremil
  • 13
  • 3
0
votes
1 answer

c++ generic programming with templates and nullptr

Let's say that I have this generic function: template void foo(T data) { if(data == nullptr) return; //... } The problem is that I can not really write something like that. If T is a primitive type or an object passed by value, I…
Kami
  • 1,079
  • 2
  • 13
  • 28
0
votes
1 answer

Overloaded function with nullptr not called

I have the following: void func(const char *p) { std::cout << p << "\n"; } void func(std::nullptr_t p) { std::cout << "\n"; } int main() { func("test"); char *p=nullptr; func(p); func(nullptr); return 0; } func("test") is…
slashmais
  • 7,069
  • 9
  • 54
  • 80
0
votes
1 answer

dynamic_cast return null pointer

For fun I decided to try to make a simple entity component system. I have a list that contains all Components and I made a function called getPositionComponent that takes the entity ID and returns the position component related to that entity. All…
Ziamor
  • 493
  • 1
  • 7
  • 11
0
votes
5 answers

Can I store nullptr to bool?

I have a function that returns a pointer to an object of type bool for a given name. If the object is not found, nullptr is returned. Now I would like to set a variable to the value of the returned boolean or false if not found. Can I write it like…
danijar
  • 32,406
  • 45
  • 166
  • 297
0
votes
0 answers

Node points to previous node but there is no previous node. Causes memory write error

This is the section that messes up. It's meant to de-reference _head->prev to a nullptr but if there is no prev it crashes so I'm attempting to handle that crash. When it gets to if( _head ) (!_head->prev) It messes up as there is no previous.…
J-Americano
  • 188
  • 1
  • 10
0
votes
2 answers

compile-time check with const char* (nullptr)

I have a template class that takes a string literal as parameter. The code works fine - but I've got one question, whether it is possible to use compile-time check to skip the generating of if (S) or else block body at all? (Something like the…
0
votes
2 answers

Manually deleting a pointer returned by function

Let's say i have this code. int* Func(std::vector integers) { for (int i : integers) { if (something) { return &i; } } return nullptr; } int* x = Func({3, 4, 5, 6, 7}); delete(x); ??? Should i…
user361633
  • 203
  • 1
  • 11
0
votes
1 answer

when we need to pass nullptr to an object^ or EventArgs ? and why to pass EventArgs::Empty to EventArgs^?

I have a method in my code, it's name is bindingSource_PositionChanged. the definition of it is: private: System::Void bindingSource_PositionChanged(**System::Object^ sender, System::EventArgs^ e**) { toolStripStatusLabel->Text =…
0
votes
2 answers

Null function pointers in a new object aren't actually nullptr

I am using C++(11) w/ Visual Studio 2012. I create windows using a custom made wrapper class. CUIWindow* winA = new CUIWindow ( NULL, TEXT("winAClassName"), TEXT("winACaption"), 200, 300 ); Each window has a series of "sockets" for pluggabe…
kvanbere
  • 3,289
  • 3
  • 27
  • 52