Answers 853
D
45: myClass obj2;
46: obj2.ShowMember();
47: cout << “Static: “ << myClass::GetStatic() << endl;
48:
49: myClass obj3;
50: obj3.ShowMember();
51: cout << “Static: “ << myClass::GetStatic() << endl;
52: return 0;
53: }
- The following is one possible answer:
0: // Ex1504.cpp
1: #include
2: using namespace std;
3: class myClass
4: {
5: public:
6: myClass();
7: ~myClass();
8: void ShowMember();
9: static int GetStatic();
10: private:
11: int itsMember;
12: static int itsStatic;
13: };
14:
15: myClass::myClass():
16: itsMember(1)
17: {
18: itsStatic++;
19: }
20:
21: myClass::~myClass()
22: {
23: itsStatic--;
24: cout << “In destructor. ItsStatic: “ << itsStatic << endl;
25: }
26:
27: void myClass::ShowMember()
28: {
29: cout << “itsMember: “ << itsMember << endl;
30: }
31:
32: int myClass::itsStatic = 0;
33:
34: int myClass::GetStatic()
35: {
36: return itsStatic;
37: }
38:
39: int main()
32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 853