30.06.2013 Aufrufe

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

MEHR ANZEIGEN
WENIGER ANZEIGEN

Erfolgreiche ePaper selbst erstellen

Machen Sie aus Ihren PDF Publikationen ein blätterbares Flipbook mit unserer einzigartigen Google optimierten e-Paper Software.

268 10. Memory – e<strong>in</strong> kle<strong>in</strong>es Beispiel<br />

23 protected :<br />

24<br />

25 /∗ This v a r i a b l e holds the s i n g l e i n stance o f t h i s d e l e t o r .<br />

26 ∗ To obta<strong>in</strong> t h i s <strong>in</strong>stance , getInstance has to be c a l l e d<br />

27 ∗/<br />

28 static DontDelete d e l e t o r ;<br />

29<br />

30 /∗ This c l a s s i s implemented as a s i n g l e t o n , so the constructor<br />

31 ∗ must not be public .<br />

32 ∗/<br />

33 DontDelete ( ) { }<br />

34<br />

35 /∗ This c l a s s i s implemented as a s i n g l e t o n , so the d e s t r u c t o r<br />

36 ∗ must not be public .<br />

37 ∗/<br />

38 virtual ˜ DontDelete ( ) { }<br />

39 public :<br />

40<br />

41 /∗ This method i s used to obta<strong>in</strong> an i n s t a n c e o f the d e l e t o r<br />

42 ∗/<br />

43 static DontDelete & getInstance ( )<br />

44 {<br />

45 return ( d e l e t o r ) ;<br />

46 }<br />

47<br />

48 /∗ This i s the dummy c a l l b a c k implementation that does not<br />

49 ∗ d e l e t e anyth<strong>in</strong>g . . .<br />

50 ∗ @param obj The po<strong>in</strong>ter to the o b j e c t to be deleted<br />

51 ∗/<br />

52 virtual void deleteObject ( void ∗ obj ) {}<br />

53<br />

54 } ;<br />

55<br />

56<br />

57 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

58 /∗ A concrete d e l e t o r f o r char ∗ elements<br />

59 ∗/<br />

60<br />

61 class CharDeletor : public ObjectDeletor<br />

62 {<br />

63 private :<br />

64 /∗ Copy construction i s not allowed<br />

65 ∗/<br />

66 CharDeletor ( const CharDeletor& s r c ) {}<br />

67 protected :<br />

68<br />

69 /∗ This v a r i a b l e holds the s i n g l e i n s t a n c e o f t h i s d e l e t o r .<br />

70 ∗ To obta<strong>in</strong> t h i s <strong>in</strong>stance , getInstance has to be c a l l e d<br />

71 ∗/<br />

72 static CharDeletor d e l e t o r ;<br />

73<br />

74 /∗ This c l a s s i s implemented as a s i n g l e t o n , so the constructor<br />

75 ∗ must not be public .<br />

76 ∗/<br />

77 CharDeletor ( ) { }<br />

78<br />

79 /∗ This c l a s s i s implemented as a s i n g l e t o n , so the d e s t r u c t o r<br />

80 ∗ must not be public .<br />

81 ∗/<br />

82 virtual ˜ CharDeletor ( ) { }<br />

83 public :<br />

84<br />

85 /∗ This method i s used to obta<strong>in</strong> an i n stance o f the d e l e t o r<br />

86 ∗/<br />

87 static CharDeletor & getInstance ( )<br />

88 {

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!