need a little help passing class info into a function

im trying to change the information in the class within a function. some help would be greatly appreciated

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
  #include <iostream>
using namespace std;

class Rectangle {
  int width, height;
public:
	void setH(int h);
	Rectangle::Rectangle():width(5),height(5) {}
	int area(void) { return width * height; }
};
 void Rectangle::setH(int h)
{
	height = h;
}

 void Changes(Rectangle*); // not sure if im passing the information correctly here

int main() {
  
  Rectangle * baz;
  
  baz = new Rectangle[2] ;
  cout << "baz[0]'s area:" << baz[0].area() << '\n';
  cout << "baz[1]'s area:" << baz[1].area() << '\n';       
  
  Changes(baz);
	
  cout << "baz[0]'s area:" << baz[0].area() << '\n';
  cout << "baz[1]'s area:" << baz[1].area() << '\n';      
	system("pause");
	return 0;
}
void Changes(Rectangle*) // not sure if im passing the information correctly here
{
	baz.setH(8);     // this is my problem here. i dont know how to change the value in the baz[0] or baz[1]
}
1
2
3
4
void Changes(Rectangle* in) // not sure if im passing the information correctly here
{
	in[0].setH(8);     // etc.
}
Thank you very much that seemed to work
Topic archived. No new replies allowed.