-
Notifications
You must be signed in to change notification settings - Fork 0
/
13_4.cpp
38 lines (34 loc) · 856 Bytes
/
13_4.cpp
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
//example on constructors and destructors
#include <iostream>
using namespace std;
class CRectangle
{
int *width, *height;
public:
CRectangle(int, int);
~CRectangle();
int area(void)
{
return (*width * *height);
}
};
CRectangle::CRectangle(int a, int b)
{
width = new int;
height = new int;
*width = a;
*height = b;
}
CRectangle::~CRectangle()
{
delete width;
delete height;
}
int main()
{
CRectangle rect(8,10), rectb(9,9);
cout << "rect area: " << rect.area() << endl;
cout << "rectb area: " << rectb.area() << endl;
getchar();
return 0;
}