B
Bit Byte
I was trying to put together a little utility generic collection class
like so:
template <class T>
class Collection
{
public:
Collection();
Collection(const Collection&);
Collection& operator= (const Collection&);
virtual ~Collection();
size_t size() const ;
bool isBOF() const ;
bool isEOF() const ;
void goToFirst() ;
void goToLast();
moveNext();
movePrev();
T item();
T item(size_t) ; //throws array bounds exception
protected:
vector<T> m_col ; // <- dosen't work (obviously ;-) )
}
There are two problems here:
1). I don't want to use specialized templates - because I want the class
to be a truly generic container
2). I want to be able to also handle a collection of pointers (stored
as smart ptrs) - if need be
-- Any ideas on how to store the various types (including pointers?)
like so:
template <class T>
class Collection
{
public:
Collection();
Collection(const Collection&);
Collection& operator= (const Collection&);
virtual ~Collection();
size_t size() const ;
bool isBOF() const ;
bool isEOF() const ;
void goToFirst() ;
void goToLast();
moveNext();
movePrev();
T item();
T item(size_t) ; //throws array bounds exception
protected:
vector<T> m_col ; // <- dosen't work (obviously ;-) )
}
There are two problems here:
1). I don't want to use specialized templates - because I want the class
to be a truly generic container
2). I want to be able to also handle a collection of pointers (stored
as smart ptrs) - if need be
-- Any ideas on how to store the various types (including pointers?)