Advertisement
Guest User

Head Datei

a guest
Jan 30th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1.  
  2. #ifndef STR_H_INCLUDED
  3. #define STR_H_INCLUDED
  4.  
  5. class str{
  6. public:
  7. str();
  8. str(char const* x);
  9. str(str const& x);
  10. ~str();
  11.  
  12. str& operator=(char const* c);
  13. str& operator=(str const& s);
  14. str operator+(str const& x) const;
  15. str& operator+=(str const& k);
  16.  
  17.  
  18.  
  19. template <class T> T operator+(T const& s){
  20. T temp(a);
  21. return temp+=s;
  22. }
  23.  
  24. template<class T> struct A{
  25. T* s;
  26. int *zaehler;
  27.  
  28. A(){
  29. s = new T();
  30. zaehler = new int(1);
  31. }
  32.  
  33. ~A(){
  34. if(--*zaehler==0){
  35. delete s;
  36. delete zaehler;
  37. }
  38.  
  39. }
  40.  
  41.  
  42. A(A const& x){
  43. s = x.s;
  44. zaehler = x.zaehler;
  45. *zaehler++;
  46. }
  47.  
  48.  
  49.  
  50. A& operator = (T* x){
  51. if(--*zaehler==0){
  52. delete s;
  53. delete zaehler;
  54. }
  55. s = x;
  56. return *this;
  57. }
  58.  
  59. A& operator = (A const& a){
  60. if(--*zaehler==0){
  61. delete s;
  62. delete zaehler;
  63. }
  64. s=a.s;
  65. zaehler = a.zaehler;
  66. *zaehler++;
  67. return *this;
  68. }
  69.  
  70. T* operator ->() {return s;}
  71.  
  72. T const* operator ->() const {return s;}
  73.  
  74. T& operator*(){return *s;}
  75.  
  76. T const& operator*()const {return *s;}
  77.  
  78.  
  79. };
  80.  
  81. private:
  82. int length;
  83. char* a;
  84.  
  85. };
  86.  
  87. #endif // STR_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement