hello this is my first time posting onto this site, and i am having a problem trying to use the private variables in the class.I believe i dont know the proper syntax to use the private part in the class.
1 2 3 4 5 6 7 8
friend statistician operator *
(double scale, const statistician & s);
private:
int count; // How many numbers in the sequence
double total; // The sum of all the numbers in the sequence
double tinyest; // The smallest number in the sequence
double largest; // The largest number in the sequence
};
here is part of the class, and the private portion. This is the multiplication operator giving me a cant change the modifiable value error. I tried just multiplying the class and not every variable at a time.
The problem isn't with accessing private variables, it's because you're trying to modify a const object:
1 2 3 4 5
statistician operator*(double scale, const statistician & s) // <- s is const
{
if(s.length() == 0)
{
s.count = scale*s.count; // <- so you can't modify it here!
You wouldn't want to modify s here anyway, since that would have weird side effects. The * operator typically creates another object, modifies that, and returns it: