How to avoid C++ anonymous objects

后端 未结 7 1709
甜味超标
甜味超标 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:15

    No, unfortunately there is no way to do this, as I explored in a blog post last year.

    In it, I concluded:

    I guess the moral of the story is to remember this story when using scoped_locks.


    You can try to force all programmers in your team to use a macro, or a range-for trick, but then if you could guarantee that in every case then you'd be able to guarantee catching this bug in every case also.

    You are looking for a way to programmatically catch this specific mistake when it's made, and there is none.

    0 讨论(0)
提交回复
热议问题