I have a C++ project with a lot of templates and it fails to compile with
fatal error C1060: compiler is out of heap space
As suggested by Hans Passant in the comments the solution to this problem was to change the Executable Directories with the one's that point to the 64bit binaries. To do this you need to go to C++ project properties -> VC++ Directories -> Executable Directories in Visual Studio and replace the value with $(VC_ExecutablePath_x64_x64);$(WindowsSDK_ExecutablePath_x64);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(FxCopDir);$(PATH)
This change makes Visual Studio use 64 bit C++ compiler.