Hate to ask this, because I've worked around it in the past, but I can't recall how to fix this issue.
So I have an assignment in a class, I can only have one public data member, that of which I already have "r" for the ratio in a geometric series.
One of my member functions needs to calculate the series partial sum (taking in a variable "n") for the number of summations, easy enough, could do this in 30 seconds with an additional data member. But I can't have that data member. I also can't pass in "sum" as an argument to the member function.
Also, apparently one cannot use local variables inside member functions (ie declaring it inside the member function such as "double sum" will not work). Does using a temp get around this? I need to return the partial sum, but I have no idea how to get a temporary variable inside my member function to hold the data until the loop is complete, and then pass it to return. Here is my code:
If you declare a local variable that is not an integral type (ie some object of a class), and that class has a default constructor, then the default constructor will be called and you don't have to initialise it. For example strings.
std::string blah;
will initialise to an empty string.
However, if you are declaring a local variable that is an integral type (eg int, double), then it will initialise to 0 if it is declared in global scope, otherwise it will remain uninitialised.
The easy way to not have to remember any of this is to always initialise.