STL / Illegal indirection error

Jan 23, 2010 at 5:05pm
I'm creating a firework display using directX and getting a compiler error that I can't quite understand why.

All my firework types, rockets, roman candles, etc. inherit from the ParticleEmitter class and have update and render methods and all work fine.
My FireworkDisplay class has a vector of pointers to derived instances and I want to iterate over the vector updating all the active fireworks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void FireworkDisplay::update()
{
	for(std::vector<ParticleEmitter*>::iterator pF(fireworks_.begin()); pF != fireworks_.end(); ++pF)
	{
		*(*pF) ->update();
	}
}

void FireworkDisplay::render()
{
	for(std::vector<ParticleEmitter*>::iterator pF(fireworks_.begin()); pF != fireworks_.end(); ++pF)
	{
		*(*pF) ->render();
	}
}


For the line *(*pF) ->update(); i get a dropdown list of my firework's methods so I don't get why i'm getting error C2100: illegal indirection for those lines. Any advice on how to get around this would be greatly appreciated, in my mind this code should be perfectly fine. Thanks.
Jan 23, 2010 at 5:12pm
For the line *(*pF) ->update(); i get a dropdown list of my firework's methods


pF is a an iterator to a ParticleEmitter*
therefore
(*pF) is a ParticleEmitter*
therefore
(*pF)->render(); properly called ParticleEmitter::render

So the additonal * serves no purpose. Get rid of it
Jan 23, 2010 at 5:23pm
Give that we have a vector of pointers vector<ParticleEmitter*> and an iterator to this vector, then
*pF will return a pointer to ParticleEmitter ParticleEmitter*.
We then want to call a function from the ParticleEmitter object through this pointer so we will have:
(*pF) ->render()



What you have written is *(*pF) ->render() which because of operator precedence is the same as *((*pF) ->render())which would call the function and then try to dereference the return value of the function which would only work if the return from the render function is a pointer.
Jan 23, 2010 at 5:40pm
Makes perfect sense, thankyou for the swift response.
Topic archived. No new replies allowed.