Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Method 1:</strong> Use the <code>#pragma warning</code> directive.</p> <p><code>#pragma warning</code> allows selective modification of the behavior of compiler warning messages.</p> <pre><code>#pragma warning( push ) #pragma warning( disable : 4705 ) // replace 4705 with warning number ScopeGuard close_guard = MakeGuard( &amp;close_file, file ); #pragma warning( pop ) </code></pre> <p>This code saves the current warning state, then it disables the warning for a specific warning code and then restores the last saved warning state.</p> <p><strong>Method 2:</strong> Use a workaround like the following. Visual Studio will be happy and so will you. This workaround is used in many Microsoft samples and also in other projects.</p> <pre><code>ScopeGuard close_guard = MakeGuard( &amp;close_file, file ); close_guard; </code></pre> <p>Or you can create a <code>#define</code> to workaround the warning.</p> <pre><code>#define UNUSED_VAR(VAR) VAR ... ScopeGuard close_guard = MakeGuard( &amp;close_file, file ); UNUSED_VAR(close_guard); </code></pre> <hr> <p>Some users stated that the code presented will not work because ScopeGuard is a typedef. This assumption is wrong.</p> <p><a href="http://www.ddj.com/cpp/184403758" rel="nofollow noreferrer">http://www.ddj.com/cpp/184403758</a></p> <blockquote> <p>According to the C++ Standard, a reference initialized with a temporary value makes that temporary value live for the lifetime of the reference itself.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload