Possible Duplicate:
prohibiting instantiation as a temporary object (C++)
I use a Scopeguard for locking like this (simplified):
{ ScopeGuard sg(mutex); // ...critical code }
I accidently typed in some place
{ ScopeGuard(mutex); // ...critical code }
which is valid code but does not extend the lifetime of the ScopeGuard object past the statement.
Question: Is there any pattern that will result in a compiler error or warning if I create a temporary ScopeGuard object like in the second e开发者_运维百科xample?
I'd leverage the preprocessor to define a lock pseudo-keyword, as described here: http://www.curly-brace.com/lock.html
精彩评论