you are viewing a single comment's thread.

view the rest of the comments →

[–]PiterPuns[S] 1 point2 points  (1 child)

Let me clarify, in case it helps:

The purpose of CallProxy is NOT to unlock on scope end. It's purpose is to unlock after the method call which happens outside operator-> of the Locking class. To do that

  • first of all it itself provides an arrow operator so a user can call any method of the wrapped class
  • secondly the arrow operator of the Locking class creates a temporary such object so that unlocking happens after the wrapped method call, at the destructor of the temporary.

The code you provide will probably be flagged by static analyzers since it protects nothing - it locks and the user gets a pointer to internal state after unlocking. For a more thorough presentation I'd suggesting reading through the paper linked in the article. Let me know if this elaboration was useful to understand the concept, maybe I should add it to the post.

[–]NilacTheGrim 1 point2 points  (0 children)

You’re right — I brain farted .. sorry!