I have tried this code in a totally separate project, and it works fine (the only difference being that the project that is not working is being exported as a DLL). Here is
The problem was I had _DEBUG defined in C/C++->Preprocessor. Changing it to NDEBUG solved the problem.