Below code does some memory corruption due to which access violation happens at sub subsequent steps
If I remove this block of code every thing is working fine. Unable to figure out the issue in the below code. Please help
You are unlikely to get a valid answer doing it like that. You should use something like sprintf to convert the double value to a string and set the actual number of decimal places that you want in the format string.
As per what David has explained all doubles are actually stored subtly different to what you think because they round. I just want to extend why they round.
They round because the computer works in base 2 (0 and 1's) and you are working in decimal base 10 (0,1,2,..9)
10 does not work as a power of 2 you can go either side 2x2x2=8 OR 2x2x2x2=16 so any base 10 decimal fraction when written in base 2 will likely round
I'm doing an assignment and it was told that SIZE of the array has to be const and also that I will need to create an assignment operator, but idk maybe my lecturer didn't think about it?
I have this code:
const int SIZE; // Size of the array
string* mp_list; //points to the start of the array
And then there's assignment operator
NameList NameList::operator = (const NameList &otherList)
SIZE = otherList.SIZE; // DOES NOT WORK
mp_list = new string[SIZE]; // Creating an array with a new size
*mp_list = *otherList.mp_list; // copying content of the other array
This will not work since you can't change const. But it's bad if I don't change the SIZE variable. Is there a way to create an assignment operator with const variable? Or is it ok if the size of the array is not const or it's bad programming? What would you do?