Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef STR_H_INCLUDED
- #define STR_H_INCLUDED
- class str{
- public:
- str();
- str(char const* x);
- str(str const& x);
- ~str();
- str& operator=(char const* c);
- str& operator=(str const& s);
- str operator+(str const& x) const;
- str& operator+=(str const& k);
- template <class T> T operator+(T const& s){
- T temp(a);
- return temp+=s;
- }
- template<class T> struct A{
- T* s;
- int *zaehler;
- A(){
- s = new T();
- zaehler = new int(1);
- }
- ~A(){
- if(--*zaehler==0){
- delete s;
- delete zaehler;
- }
- }
- A(A const& x){
- s = x.s;
- zaehler = x.zaehler;
- *zaehler++;
- }
- A& operator = (T* x){
- if(--*zaehler==0){
- delete s;
- delete zaehler;
- }
- s = x;
- return *this;
- }
- A& operator = (A const& a){
- if(--*zaehler==0){
- delete s;
- delete zaehler;
- }
- s=a.s;
- zaehler = a.zaehler;
- *zaehler++;
- return *this;
- }
- T* operator ->() {return s;}
- T const* operator ->() const {return s;}
- T& operator*(){return *s;}
- T const& operator*()const {return *s;}
- };
- private:
- int length;
- char* a;
- };
- #endif // STR_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement