C++ array 探索1
template <class T>
class Array
{
public:
typedef Array __self;
typedef T value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef value_type* iterator;
typedef const value_type* const_iterator;
public:
Array(int size)
{
_size = size;
_arr = new value_type[size];
}
~Array()
{
delete[] _arr;
_arr = nullptr;
}
public:
__self::iterator begin() throw()
{
return &_arr[0];
}
__self::iterator end() throw()
{
return &_arr[_size];
}
__self::reference operator[](int index) throw()
{
return _arr[index];
}
__self::const_reference operator[](int index) const throw()
{
return _arr[index];
}
__self::reference at(int index)
{
return _arr[index];
}
__self::const_reference at(int index) const
{
return _arr[index];
}
void operator()(int index, value_type val)
{
_arr[index] = val;
}
private:
value_type *_arr;
int _size;
};