Thread: A lil help?

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    2

    A lil help?

    I don't really understand C++ that well, even though I've got a class thats supposed to be teaching me it. We have an assignment due in a few days that I tried writing, but it won't compile, and I can't understand why.
    Its supposed to be a rubber array. Can anyone help?

    Code:
    #include <iostream>
    
    
    using namespace std;
    
    template <class T> class RubberArray
    {
      T* _a;
      unsigned _alloc;
      unsigned _len;
      signed _zero;
    public:
    RubberArray<T> ( int i = 0) 
    {
      _len = i;
      _alloc = 0;
      _a = NULL;
    };
    // i is the index of the first element in your RubberArray
    
    RubberArray(const RubberArray<T>& RA)
    {
      _alloc = 0;
      _len = 0;
      _a = NULL;
      for (int i = _zero;i<(_len+_zero);i++)
        add(RA[i]);
    };
    
    void dele (int i)
    {
      //check i out of range
      RubberArray<T> temp(_zero);
      signed r;
      for(r = _zero;r<(_zero+_len);r++);
      {
        if(r!=i)
          temp.add(operator[](r));
      }
      *this=temp;
    };
    
    RubberArray<T> operator() (int first ,int last) const
    {
      if ((first<_zero)||(last>(_zero+_len))||(first>=last));
      {
        //error
      }
      RubberArray<T> Ret(_zero);
      int i;
      for (i = first;i<last;i++)
        Ret.add(operator[](i));
      return Ret;
    };
    
    void add(const RubberArray<T>& RA)
    {
      unsigned i;
      for(i = 0;i<RA._len;i++);
        add(RA._a[i]);
    
    };
    
    void dele (int first, int last)
    {
      //check i out of range
      int i;
      for(i=first;i<last;i++) 
        dele(first);
    };
    
    void insert(const T& item)
    {
      RubberArray<T> temp(_zero);
      temp.add(item);
      temp.add(*this);
      *this=temp;
    };
    ~RubberArray ()
    {
      delete [] _a;
    };
    
    RubberArray& operator= ( const RubberArray& ra)
    {
      if ( &ra == this )
        return ( *this );
      _zero = ra._zero;
      if ( _alloc != 0 )
       { delete [] _a;}
      _len = 0 ;
      _alloc = 0 ;
      _a = NULL;
      for ( int i = 0 ; i < ra._len; i++ )
        add( ra._a[i] );
      return ( *this );
    };
    
    // return the number of items in the array
    unsigned length () const
    {
      return _len;  
    };
    
    RubberArray ( const T* ra, unsigned s, int i = 0 )
    {
      _alloc = s;
      _len = s;
      _zero = i;
      _a = NULL;
    };
    // i is the index of the first element in your RubberArray
    // s is the number of items pointed to by T*
    //  access the item at index 0<=i<length (assuming standard indexing)
    
    T& operator[] ( int i )
    {
      return _a[i];
    };
    
    const T& operator[] ( int i ) const
    {
      return _a[i];
    };
    
    void add ( const T& old)
    {
      unsigned i;
      for(i=(_len + 1);i<(_len + old._len);i++);
      {
        add(old._a[i]);
      }
    };
    
    friend ostream& operator<< ( ostream& os, const RubberArray<T>& RA)
    {
      os << "Values are: ";
      int i; 
      for (i = 0; i < RA._len; i++ )
        os << RA._a[i]; 
    os<<"ostream";
      return os; 
    };
    
    friend ostream& operator<< ( ostream& os, const RubberArray<T>* RA)
    {
      os << "Values are: ";
      for ( int i = 0; i < RA._len; i++ )
        os << RA._a[i];
      return os;
    };
    // Insert at index 0<=i<length (assuming standard indexing)
    
    void insert ( int i, const T& ra)
    {
      RubberArray<T> temp;
      int t;
      for (t = 0; t> i;t++)
      {
        temp._a[t] = *this._a[t];
      }
      temp.add(ra);
      for (;t < (_len + ra._len); t++)
      {
        temp._a[t] = *this._a[t];
      }
    };
    
    };
    I appreciate any help.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    What were the compiler errors?

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    2
    Nevermind... I got it fixed with help from a friend.

    Thanks anyway..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Lil Help With Inheritance...
    By frassunit in forum C++ Programming
    Replies: 16
    Last Post: 03-04-2009, 03:54 AM
  2. A lil controversy: Cloning
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 65
    Last Post: 02-17-2003, 11:19 AM
  3. i need a lil venting.
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 01-03-2003, 10:21 PM
  4. Lil Anti Windows Humor
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-02-2002, 12:01 PM
  5. I need a lil help with OS's
    By civix in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 07-18-2002, 10:54 AM