#ifndef FIXEDCONTAINER_H
#define FIXEDCONTAINER_H
#include <iostream>
#include <stdexcept>
using namespace std;
template <class T>
class FixedContainer : public BaseContainer<T>
{
public:
FixedContainer(int length);
virtual ~FixedContainer();
int getSize() const;
T getValue(const int index) const ;
void setValue (const int index,T value);
T operator [] (int index) const ;
T &operator [] (int index) ;
private:
int _length;
T *_data;
};
template <class T>
FixedContainer<T>::FixedContainer(int length)
: _length(length)
{
_data=new T[_length];
}
template <class T>
FixedContainer<T>::~FixedContainer()
{
delete [] _data;
}
template <class T>
int FixedContainer<T>::getSize() const{
return _length;
}
template <class T>
T FixedContainer<T>::getValue(const int index) const{
if(index >=0 && index < getSize()){
return _data[ index ];
}else{
throw invalid_argument("Dizi s�ras� s�n�rlar�n alt�nda!" );
}
}
template <class T>
void FixedContainer<T>::setValue(const int index,T value){
if(index >=0 && index < getSize()){
_data[ index ]=value;
}else{
throw invalid_argument("Dizi s�ras� s�n�rlar�n alt�nda!" );
}
}
template <class T>
T FixedContainer<T>::operator[](int index) const{
return _data[index];
}
template <class T>
T &FixedContainer<T>::operator[](int index) {
return _data[index];
}
#endif
Dosyayı İndir