开发者

Scopeguard lifetime / pattern needed [duplicate]

This question already has answers here: Closed 12 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜