template iterators

S

springer

Hi,

I have a template matrix class that wraps a std::vector. However, the
compiler is complaining about this:

typedef std::vector<T>::iterator iter;
typedef std::vector<T>::const_iterator citer;

iter begin(){ return mMatrix.begin(); }
iter end() { return mMatrix.end(); }

citer begin() const { return mMatrix.begin(); }
citer end() const { return mMatrix.end(); }

Any ideas? It compiles on VC++ 2002, but not on VC++ 2003.
 
V

Victor Bazarov

springer said:
I have a template matrix class that wraps a std::vector. However, the
compiler is complaining about this:

typedef std::vector<T>::iterator iter;
typedef std::vector<T>::const_iterator citer;

iter begin(){ return mMatrix.begin(); }
iter end() { return mMatrix.end(); }

citer begin() const { return mMatrix.begin(); }
citer end() const { return mMatrix.end(); }

Any ideas? It compiles on VC++ 2002, but not on VC++ 2003.

Throw away VC++ 2002. Keep using 2003. Add the 'typename' right
after 'typedef'. Example:

typedef typename std::vector<T>::iterator iter;

V
 
M

mlimber

springer said:
Hi,

I have a template matrix class that wraps a std::vector. However, the
compiler is complaining about this:

typedef std::vector<T>::iterator iter;
typedef std::vector<T>::const_iterator citer;

iter begin(){ return mMatrix.begin(); }
iter end() { return mMatrix.end(); }

citer begin() const { return mMatrix.begin(); }
citer end() const { return mMatrix.end(); }

Any ideas? It compiles on VC++ 2002, but not on VC++ 2003.

It's unclear. Post more of the code, and show us the error messages.

Is your matrix 2-D? That is, does mMatrix.begin() actually return
std::vector< vector<T> >::iterator? (Doubtful, but just in case.)

Cheers! --M
 

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
474,470
Messages
2,571,809
Members
48,797
Latest member
PeterSimpson
Top