How to avoid C++ anonymous objects

后端 未结 7 1715
甜味超标
甜味超标 2020-12-06 10:21

I have a ScopedLock class which can help to release lock automatically when running out of scope. However, the problem is: Sometimes team members write invalid

7条回答
  •  隐瞒了意图╮
    2020-12-06 11:12

    In C++17, a type can be marked [[nodiscard]], in which case a warning is encouraged for an expression that discards a value of that type (including by the case described here that resembles a declaration of a variable). In C++20, it can be applied to individual constructors as well if only some of them cause this sort of problem.

提交回复
热议问题