Closed CapitanLiteral closed 7 years ago
Hi, it looks like you have some sort of run time error checking enabled. In practice the variable not being initialized doesn't matter at all since it gets overwritten by the parser, but for cleanliness' sake I committed a patch to make sure the variable is default initialized. Your fix works perfectly fine, but my preferred fix is T temp{};
instead of
static T temp;
User CaptainLiteral reported runtime debug error check where makeTemp() asserted that T was not initialized; The declaration :
T temp;
default constructs a class variable, but leaves primitive types (in this case int) uninitialized. A solution proposed for this was to make T static, since static variables are default initialized according to the C++ standard.
However, C++11 brace initializer ({}, without equals sign) default initializes POD primitive data types and classes both; To me this is semantically closer to what we’re actually trying to do and C++11 should be fairly universal at this point so this is my preferred fix.
I dont really know why, but if I don't put this var in static it gives me a runtime exeption when I use "sum" command or "sumFive"
Run-Time Chech Failure #3 - The variable 'temp' is being used without being initialized
but when I do it stops failing. Whatch it and tell me please, I'll be glad to learn why or why don't.