background image

50     mValue = -1;
51 }
52
53 int MyClass::GetValue() const
54 {
55     return (mValue);
56 }
57
58 void MyClass::SetValue(int     inValue)
59 {
60     assert(IsValid());
61     mValue = inValue;
62 }
63
64 bool MyClass::IsValid() const
65 {
66     return (0 <= inValue && inValue <= 1000);
67 }
68
69 MyClass* MyClass::GetInstance()
70 {
71     if (sInstance == 0) {
72         sInstance = new MyClass();
73     }
74     return (sInstance);
75 }

复制代码

    

Objective-C

76 #import "MyClass.h"
77
78 static MyClass* sInstance = 0;
79
80 @implementation MyClass
81
82 - (int)         getValue
83 {
84     return (mValue);
85 }
86
87 - (void)     setValue:  (int)         inValue
88 {