PDA

View Full Version : Error when trying to pass STL List by reference


Accumulator A
07-30-2005, 11:31 AM
The title mostly says it all. I don't know if it's possible or not, but it seems like it should be so I tried it anyway.

The error I get is:

error:invalid use of template-name 'std::list' without an argument list

Relevant bits of code follow


using namespace std;
list<Particle> list1;
list<Particle>::iterator pit;
list createParticleExplosion(list<Particle>, int, float, float, float, float,float,float);

int main(void){
list1 = createParticleExplosion(list1, 20, 300, 250, 147, 7500,10,300);
}//end main

list createParticleExplosion(list &bro, int partamount, float posx, float posy, float changle, float speed,float decay, float lifetime){
//the function
}//end createParticleExplosion


I originally wanted this function to return void, but when I had it as void it was giving me the error "variable or field 'createParticleExplosion' declared void." Is it possible to have this function be void?

Also how would I handle passing the list iterator?

I'm sure I'm just messing up the syntax or something, but I couldn't find an answer via google, my various c++ books or comp.lang.c++.

Thanks!

Jim Buck
07-30-2005, 12:02 PM
"list" is an incomplete type. It has to be a list of *something*. So, "createParticleExplosion"'s return value and 1st argument must have "list<sometype>" where "sometype" is the type of your list.

Accumulator A
07-30-2005, 12:23 PM
changed code to using void and list<Particle> instead of list


using namespace std;
list<Particle> list1;
list<Particle>::iterator pit;
void createParticleExplosion(list<Particle>, int, float, float, float, float,float,float);

int main(void){
createParticleExplosion(list1, 20, 300, 250, 147, 7500,10,300);
}//end main

void createParticleExplosion(list<Particle> &bro, int partamount, float posx, float posy, float changle, float speed,float decay, float lifetime){
//the function
}//end createParticleExplosion


It compiles but when I press a key (to run this bit of code) it exits and gives me this error: (I'm using Xcode)

ZeroLink: unknown symbol '__Z23createParticleExplosionSt4listI8ParticleSaIS 0_EEiffffff'
particletest has exited due to signal 6 (SIGABRT).

What does that exactly mean?

SimmerD
07-30-2005, 03:49 PM
You are wrongly forward declaring your list<Particle> instead of list<Particle>&

Accumulator A
07-30-2005, 04:32 PM
You are wrongly forward declaring your list<Particle> instead of list<Particle>&

Thanks! That was exactly the problem. I'm a C++ newbie so I'm rusty on those issues.

How exactly would I go about passing the list iterator?

Jim Buck
07-30-2005, 07:56 PM
list<Particle>::iterator &itParticle

mahlzeit
07-31-2005, 03:04 AM
I prefer to use typedefs to make things more readable:
typedef std::list<Particle> ParticleList;
typedef ParticleList::iterator ParticleIter;

void someFunction(ParticleList& list, ParticleIter& i)
...