Linked Questions

0 votes
1 answer
537 views

I would like to replace code like this: if ((obj != nullptr) && obj->is_valid()) with if (obj->is_valid()) where class Obj { bool is_valid() { if (this == nullptr) ...
segfault's user avatar
  • 519
1 vote
2 answers
223 views

Lets say I have the following class struct FooList { int data; FooList *next; // basic constructor FooList(int d, FooList *n): data(d), next(n) {} // basic destructor ~...
randomusername's user avatar
3 votes
0 answers
322 views

Let's consider this piece of code: struct config { int get( ) { if ( this == nullptr ) return 1; return value; } int value = 5; }; config* c = nullptr; int result = ...
Kornel Kisielewicz's user avatar
0 votes
0 answers
136 views

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 ...
Arnav Borborah's user avatar
0 votes
0 answers
77 views

I have seen C++ classes that check the this pointer to make sure it is not nullptr before using a field. Here is a simplified example of what I'm talking about: #include <iostream> class object ...
Alexis Wilke's user avatar
  • 21.2k
120 votes
11 answers
30k views

Saw this line in a class method and my first reaction was to ridicule the developer that wrote it.. But then, I figured I should make sure I was right first. public void dataViewActivated(...
Bryce Fischer's user avatar
150 votes
5 answers
10k views

GCC 6 has a new optimizer feature: It assumes that this is always not null and optimizes based on that. Value range propagation now assumes that the this pointer of C++ member functions is non-null. ...
boot4life's user avatar
  • 5,422
76 votes
11 answers
7k views

If I come across old code that does if (!this) return; in an app, how severe a risk is this? Is it a dangerous ticking time bomb that requires an immediate app-wide search and destroy effort, or is it ...
Crashworks's user avatar
  • 41.6k
0 votes
2 answers
2k views

In Qt I have to wait for 1 second and let event process so I use QTime lDieTime= QTime::currentTime().addSecs(1); while (QTime::currentTime() < lDieTime) QCoreApplication::processEvents(...
David Levy's user avatar
1 vote
3 answers
157 views

Let's say whe have class Foo{ public: bool error; ...... bool isValid(){return error==false;} }; and somewhere Foo *aFoo=NULL; I usually would do if (aFoo!=NULL && ...
tru7's user avatar
  • 7,382
1 vote
2 answers
2k views

I need call native method like that: java code: private native Object SendFiles(String strEmail, DeviceInfo info, String [] arrFiles, int cntFiles, ID idRequest); call SendFiles(); SendFiles(...
koleanu's user avatar
  • 495
0 votes
1 answer
671 views

I have to call a function of a class from another function of the same class. But the problem is for some cases the current object can be destroyed. So for this case calling the function is creating ...
ksohan's user avatar
  • 1,199
1 vote
1 answer
109 views

This is not about explicit code, so apologies if it should have been posted elsewhere. It is, however, solidly within the domain of testing, which I assume you guys to be right at home in. I'm ...
KlaymenDK's user avatar
  • 732