"Clean" then "Rebuild" and now it works. WTF???
Here's what could have happened (this happens from time to time):
Multiple source (.cpp) files are individually compiled into object files (.obj, or .o). Then the linker comes along and links all these object files together and creates one big executable (.exe) out of them. Compiling and linking are two different tasks, but both can be time consuming, especially in large projects. In order to cut down the time you have to wait, the compiler will first compile all .cpp files into .obj files, and then when you change a source file and rebuild, it will only rebuild that one file that was changed (why waste time rebuilding files that haven't changed?).
This is where the problem typically comes in. In order for the compiler to do this properly, it must build a dependency graph so it knows which source files depend on which header files (so that if you change a header file, all the source files that use it can be recompiled). It's possible for the compiler to miss a dependency for some reason, or if you change two source files, the compiler doesn't realize one has changed (could be timestamp issues or something), and now the compiler only recompiles some of the source files it should have. Now you have a problem, because some object files are up to date, and some are old and didn't get updated like they should have. The linker has no clue, though, and links them all together into an executable for you. This can lead to weird things, from crashes, to garbage computations, to pretty much anything.
For example, if you have a struct in a header file that has some member int x;, and you remove the x member variable from the struct because you no longer need it, and two different source files use that struct but only one gets rebuilt by the compiler, each compiled object file will have a different memory representation and layout of that struct. Now it's just a disaster waiting to happen.
This doesn't happen a lot, but it happens enough that you should try rebuilding before declaring nuclear war on your code base.
Edited by Cornstalks, 31 December 2012 - 02:51 PM.