370 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
3
votes
1
answer
221
views
Deleting nullptr before creating the object in Qt code
I'm exploring OpenGL with Qt6, and I came across some of their examples. The thing that draws my attention from a C++ perspective is the following piece of code.
delete m_program; // <-- is this ...
2
votes
2
answers
257
views
What values other than nullptr can nullptr_t have?
The CPPReference page on reinterpret_cast mentions possible multiple distinct values of std::nullptr_t. The page for that doesn't rule that out, but also doesn't explain what such a value might be. I ...
6
votes
1
answer
129
views
Can std::bit_cast convert to or from std::nullptr_t type?
Is it prohibited to use std::bit_cast for conversion to or from std::nullptr_t = decltype(nullptr) type? And if it is permitted, 1) must the result of std::bit_cast be the same as static_cast, 2) must ...
4
votes
1
answer
99
views
inconsistent deduction with decltype(auto) when returning pointer or nullptr
When using decltype(auto) as return type of a template function that is supposed to return a pointer, I've got an issue when this function can return a valid address or nullptr.
Here is an example:
...
4
votes
1
answer
176
views
How to get a typed nullptr "literal"?
I just found out that std::is_pointer_v<nullptr> translates to false, thats why the code below:
template <typename T> std::string_view type_str() { /* returns the name of the type */ }
...
1
vote
2
answers
171
views
C23 and memory representation of nullptr
I'm reading the C document n3042 Introduce the nullptr constant
and when it enumerates the properties of nullptr there is the following:
In memory, nullptr is represented with the same bit-pattern as ...
1
vote
1
answer
302
views
Unreal Engine Replication of TArrays of Object type
My Goal is to replicate a TArray<UHealthComponent*> in a ListenServer configuration for 2 players
For more context the TArray is inside of an ActorComponent named ShipStats attached to the ...
0
votes
0
answers
327
views
Can "nullptr" fully replace "NULL" in C23?
Is NULL fully interchangeable with nullptr in C23? Are they used in separate scenarios?
I'm coding a game, and there are moments where I've used NULL and others where I've used nullptr. I initially ...
1
vote
2
answers
197
views
In c++ when checking for nullptr, is there a reason to use if(!(x==nullptr)) instead of if(x!=nullptr), are they different?
I'm working through a c++ course and currently covering checking for nullptr's.
The suggested code is:
int* p{};
if(!(p==nullptr)){
etc, etc
But I'm not sure why I can't say (which seems slightly ...
14
votes
3
answers
1k
views
Overload resolution of a pointer and a container with pointers
I wrote a function with two overloads - one for a single pointer and one for a vector of pointers. At some point in the code I wanted to pass an empty vector to the function and used {} as the ...
0
votes
0
answers
71
views
Error for the nullptr in smart ponter initializatin [duplicate]
ALL,
Using MSVC 2017.
When I had the code like this:
class Foo
{
private:
LibraryObject *m_library;
};
my code compiled fine.
But when I tried to do it like this:
class Foo
{
private:
std::...
4
votes
1
answer
472
views
What is the correct way to use C23's nullptr in place of NULL?
I've been playing around with C23's new features and I came across nullptr, and I'd like to use it in place of NULL where possible, or at least in demo code to better understand proper usage.
Here is ...
-1
votes
1
answer
114
views
Singly linked list returning an error even though I have already checked it [closed]
When using a singly-linked list, I've been suggested to use "if x != nullptr" but I don't understand why this works. In my example code, the first and second print statements work, but as ...
1
vote
3
answers
355
views
What is a "known bad pointer value"?
In this answer to this question, it was noted that:
If you're going to 'clear' the pointer in the dtor, a different idiom would be better - set the pointer to a known bad pointer value.
and also ...
7
votes
2
answers
207
views
Is a non-constant zero integer cast to `void *` still a null pointer?
The expresssion (void *)0 is called a null pointer.
But how about the following:
int i = 0;
void *s = (void *)i;
Is s also a null-pointer? The C-language standard says:
6.3.2.3 Pointers
3 An integer ...