tags:

views:

298

answers:

3

I am confused.

I do this:

#include <vector>

// List iteration
typedef vector<registeredObject>::iterator iterator;
typedef vector<registeredObject>::const_iterator const_iterator;
vector<registeredObject>::iterator begin(void);
vector<registeredObject>::const_iterator begin(void) const;
vector<registeredObject>::iterator end(void);
vector<registeredObject>::const_iterator end(void) const;

I get errors like:

.: error: ISO C++ forbids declaration of 'vector' with no type
.: error: expected ';' before '<' token

for each one of the above uses of vector. This code compiles in older CodeWarrior, but XCode complains. What is the issue?

Is there a good reference?

[EDIT] Here is the entire header Here

+14  A: 

vector is in the namespace std:

typedef std::vector<registeredObject>::iterator iterator;

Also, why are you defining these types then not using them?

typedef std::vector<registeredObject> container;
typedef container::iterator iterator;
typedef container::const_iterator const_iterator;

iterator begin(void);
const_iterator begin(void) const;
iterator end(void);
const_iterator end(void) const;

Also consider that perhaps you haven't defined registeredObject. Try with int to make sure.


Now that we see registeredObject is a template parameter, you need typename:

typedef typename std::vector<registeredObject> container;
typedef typename container::iterator iterator;
typedef typename container::const_iterator const_iterator;

Here's why. Don't forget the other things, though. You still need std::, and to actually use your defined types. (This must be fixed in both of your classes.)

Note it is much more common to use T as the template type. It's then also common to be generous with your typedef's:

typedef T value_type;
typedef std::vector<value_type> container;
typedef typename container::iterator iterator;
typedef typename container::const_iterator const_iterator;

And use these in your class. (i.e., use container mRegistryList; instead)

GMan
@Gman - not sure that I understand as putting std:: before the use of vector does not seem to work either. I posted the link to the class above. I think it is templates that is confusing me.
JT
A: 

Is registeredObject declared? Have you included RegisteredObject.h?

jeffamaphone
A: 

If I had to guess, I would say that the registeredObject type is defined in a file somewhere, but is not included in this header file.

One .CPP file might happen to include RegisteredObject.h before MyIteratorDeclarations.h and this would work. But then another file might be just including MyIteratorDeclarations.h, which would then produce an error.

At the moment there isn't enough code supplied to be sure. Perhaps you can change your example to display all of the header file contents right up to the first error.

Andrew Shepherd
@Andrew: I posted the class as a txt file in the link above.
JT