If I copy this function below main it makes no difference.
I mean take the stringstream declaration, and use, and put it in a different function entirely, just for now.
>Are you suggesting that the line "ss << 15" forces instantiation of operator<< where-as without it the member function is not?
Now isn't the compiler supposed to instantiate the functions automatically when it encounters them? So would this be a compiler issue?
When it encounters them, yes, but with it commented out, it is never used; the compiler never processes what's in comments. I'm not sure if it is implementation defined, but my compiler does not instantiate a member function if it is never called, in order to cut down on executable size. This leads to frustrating bugs that I overlook, because I never used the function, thus the compiler never instantiates it and points out an obvious bug.
So, call it a long shot, but perhaps something relies on this operator <<() function being instantiated, and when it isn't instantiated in any of the objects linked together, the program crashes. This reminds me of a compiler bug discovered not too long ago, where virtual functions were being declared as inline, and thus the compiler never instantiated the function as a normal function, leading to a crash when the program attempted to access the function through the vtable.
Defining a virtual function as an inline function is legal, and has uses, but the compiler is supposed to make a normal function instantiation as well, so that it can be called via function pointer. The bug was that the normal out-of-line instantiation wasn't made, thus the function pointer pointed to garbage.
I understand that if commented out operator<<() would never be instantiated IF that was the only place it was used. In this case though it was being used in another function that was being called (in this case e.GetLineNumber()) but that is in another file which is part of a small library which is linked in. My guess is that despite being used in the library, something with the linking step is causing it to discard that instantiation, which is why the line "ss << 15" causes it to run as it forces the instantiation that should have been there in the first place. This would also explain why copy-pasting identical code from the library into main caused it to fix itself/run.
So I guess the next question is, why is the linker doing this and how can I prevent it? Did I personally do something wrong (is there a linker setting I'm not aware of?) or is this a bug with VS2012? If my hypothesis is indeed correct, I don't see how I could have been the 1st one to come across this error.
btw here is the call stack:
> Zombies.exe!std::basic_ostream<char,std::char_traits<char> >::operator<<(int _Val=34) Line 300 C++
Zombies.exe!Exception::GetLineNumber() Line 185 C++
Zombies.exe!WinMain(HINSTANCE__ * hInstance=0x00f50000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x002a375b, int nCmdShow=10) Line 39 C++
Zombies.exe!__tmainCRTStartup() Line 238 C
Zombies.exe!WinMainCRTStartup() Line 164 C
kernel32.dll!759a33aa() Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
ntdll.dll!776f9ef2() Unknown
ntdll.dll!776f9ec5() Unknown