How bad is “if (!this)” in a C++ member function?

前端 未结 11 806
不思量自难忘°
不思量自难忘° 2021-02-04 23:16

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

11条回答
  •  Happy的楠姐
    2021-02-04 23:31

    this is something that's called 'a smart and ugly hack'. note: smart != wise.

    finding all the call sites without any refactoring tools should be easy enough; break GetLookup() somehow so it doesn't compile (e.g. change signature) so you can identify misusage statically. then add a function called DoLookup() which does what all this hacks are doing right now.

提交回复
热议问题