Sticky problem with collection class

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?)
 
B

Bit Byte

Bit said:
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?)

Correction - the move* methods are of type void (before anyone points
that out)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top