开发者

Scopeguard lifetime / pattern needed [duplicate]

开发者 https://www.devze.com 2023-02-04 14:03 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: prohibiting instantiation as a temporary object (C++)
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

精彩评论

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

关注公众号