C++ – Disable single warning error

cpragmavisual c++warnings

Is there a way to disable just a single warning line in a cpp file with visual studio?

For example, if I catch an exception and don't handle it, I get error 4101 (unreferenced local variable). Is there a way to ignore this just in that function, but otherwise report it in the compilation unit? At the moment, I put #pragma warning (disable : 4101) at the top of the file, but that obviously just turns it off for the whole unit.

Best Answer

#pragma warning( push )
#pragma warning( disable : 4101)
// Your function
#pragma warning( pop )