Ok, I've come up with this function... Tell me what you think. Is this going to work, or do I have it all wrong?

Code:

MAGNET* mag_create(STRING* filename,VECTOR* pos,int pole)
{
MAGNET* tmp= malloc(sizeof(MAGNET));
tmp->pole= pole;
switch(pole)
{
case POSITIVE:
{
ENTITY* ent_post= ent_create("posmagnet.mdl",curpos,phys_objsphere);
tmp->entity= ent_post;
}
case NEGATIVE:
{
ENTITY* ent_negt= ent_create("negmagnet.mdl",curpos,phys_objsphere);
tmp->entity= ent_negt;
}
}
return tmp;
}



I looked up malloc() and sizeof() on Wikipedia. I take it what I'm doing when I write "MAGNET* tmp= malloc(sizeof(MAGNET));" is I'm allocating in memory the data size of the MAGNET struct. How do I use this to keep generating more MAGNET*s? doesn't the first MAGNET* get overwritten by the next one that is generated? Or is there more I should know about malloc()?


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}