Lifetime required / sample staples

Possible duplicate:
prohibition of creating an instance as a temporary object (C ++)

I use Scopeguard to block like this (simplified):

{
ScopeGuard sg (mutex);
// ... critical code
}

I accidentally typed in some place

{
ScopeGuard (mutex);
// ... critical code
}

which is valid code but does not extend the lifetime of the ScopeGuard object after approval.

Question: Is there any pattern that will lead to a compiler error or warning if I create a temporary ScopeGuard object, as in the second example?

+3
source share

Source: https://habr.com/ru/post/1785448/


All Articles