You don't need to create a new thread for each response that you make. This is a response to the other thread that you created today about the exact same problem...
One thing that you need to realize is that the = operator in C++ is an assignment operator. It evaluates the expression on the right, with the current values that the variables has at that point, and assigns it to the variable on the left.
1 2 3
|
void setSum(double total) {
total = vol1 + vol2;
}
|
With this in mind we can see that this function isn't good for anything. It calculates the sum of
vol1 and
vol2 and assigns the value to
total, which is a local variable, so there are no observable effects from outside the function.
I agree with what ne555 said above,
vol1 and
vol2 does not really make sense as member variables. I also don't understand the purpose of the setSum function (
What's the sum of a box?).
I also agree that it doesn't make much sense to be able to do addition with boxes. The way you have defined the + operator does not mean that the resulting box will have a volume that is equal to the sum of volumes of the two original boxes.
If the sides of box1 is 6, 7, 5, and the sides of box2 is 12, 13, 10, then adding the sides using your + operator will result in a box with the sides 18, 20, 15 which means that the volume is 5400.
If you want to calculate the sum of volumes of the two boxes the correct way would be
|
double volumeSum = box1.getVolume() + box2.getVolume();
|