-
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.
-
What were the compiler errors?
-
Nevermind... I got it fixed with help from a friend.
Thanks anyway..