Why is this not returning 125

Im writing a class to calculate the volume of a box.The values are width 5, height 5, length 5.
Why is the multiplacation function not returning 125 please?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<iostream>

using namespace std;

class Box
{
	public:
	int SetitsHeight(int height) {height = itsHeight;}
	int SetitsLength(int length){length= itsLength;}
	int SetitsWidth(int width){width = itsWidth;}
	int GetitsHeight(){return itsHeight;}
	int GetitsLength(){return itsLength;}
	int GetitsVolume(){return itsWidth*itsLength*itsHeight;}
	
	Box operator+(Box & spare)
	{
		Box box;
		box.itsWidth = this->itsWidth + spare.itsWidth;
		box.itsLength = this->itsLength + spare.itsLength;
		box.itsHeight = this->itsHeight + spare.itsHeight;
		return box;
	}
	
	private:
	int itsWidth;
	int itsLength;
	int itsHeight;
	
};

int main()
{
	Box Box1;
	Box1.SetitsHeight(5);
	Box1.SetitsWidth(5);
	Box1.SetitsLength(5);
	
	cout<<"Box1s volume is " << Box1.GetitsVolume()<< endl;
1
2
3
	int SetitsHeight(int height) {height = itsHeight;}
	int SetitsLength(int length){length= itsLength;}
	int SetitsWidth(int width){width = itsWidth;}


a = b; means that a is assigned the value of b.
You are assigning your function parameter, not your class's data member.
Switch your assignments around.
Topic archived. No new replies allowed.