tags:

views:

94

answers:

5

I have these three related class members:

vector<Frame*>* poolFrames;
vector<Frame*>*::iterator frameIterator;
vector<vector<Frame*>::iterator>* poolFrameIterators;

When I compile, gcc tells me

error: invalid use of ‘::’ error: expected ‘;’ before ‘frameIterator’

In reference to the middle line, where I define frameIterators. It goes away when I loose the pointer to the vector and make it a vector::iterator. However, I want them to be pointers. Is there a special way to define the data type that I want, or do I need to use vector::iterator and then dereference?

+1  A: 

What data type do you actually want?

vector<Frame*>* poolFrames; is a pointer to a vector of Frame pointers. Do you actually just want a vector of Frame pointers?

In that context, the error makes sense. A vector<Frame*> has iterators. A pointer to such a thing does not have iterators.

TheUndeadFish
so I need to dereference every time I want to get a pointer out of an iterator, correct?
Colin Roache
A: 

The type of vector* is a pointer, which has no iterators.

+2  A: 

If you want a pointer to an iterator do it this way round:

vector<Frame*>::iterator*

The asterisk always follows the type that is pointed to. The way you have it is pretty much like writing vector*<Frame*>::iterator, it just has the asterisk in the wrong place.

AshleysBrain
I don't think that's true. My first declaration, 'vector<Frame*>*' compiles fine while 'vector*<Frame*>' does not.
Colin Roache
It is true. In your first declaration the type pointed to is `vector<Frame*>`, and following with an asterisk gives `vector<Frame*>*`. In the second declaration, I *think* you want the type pointed to to be `vector<Frame*>::iterator`, in which case following with an asterisk gives `vector<Frame*>::iterator*`. If that's not enough I think you should clarify the question.
AshleysBrain
A: 
vector<Frame*>* 

Is a type expression but it does not have a member iterator It's kind of like using . on a pointer.

witkamp
+4  A: 

I see what you were trying to do. You've defined poolFrames as a pointer to a vector. Then you want to define frameIterator as an iterator for poolFrames. Since poolFrames is a pointer, you think you need a special pointer-to-vector iterator, but you're mistaken.

A vector iterator is a vector iterator is a vector iterator, no matter how you managed to refer to the vector in the first place. You need frameIterator to be a simple iterator:

vector<Data*>::iterator frameIterator;

To assign a value to that variable, you'll need to dereference your vector pointer, like this:

frameIterator = poolFrames->begin();

If poolFrames were a vector instead of a pointer to a vector, you'd use the dot operator instead: poolFrames.begin().

Rob Kennedy
Thank you, you actually understood what I was trying to do. That answers it all for me.
Colin Roache