Joined
·
3,672 Posts
I have a function that creates a pointer to a class, inserts some information into that class, and then stores a unique id and the pointer into a map. I haven't finished my code, but I have a suspicion that every time I call the function, it's going to cause the pointer from the previous class to point to the current class. Basically it will only create one pointer and then keep switching what it points to. Can anyone with more experience tell me if my function will for sure do this? I only ask now because it's a large program, and this is a bug I want to catch early.
Code:
Code:
Code:
int Code_Processor::New_Prize(string id, string description, int points, int quantity){
Prize *p;
map <string, Prize *>::iterator pit;
p = new Prize;
if(points <= 0){ return -1; }
if(quantity <= 0){ return -1; }
p->id = id;
p->description = description;
p->points = points;
p->quantity = quantity;
for(pit = Prizes.begin(); pit != Prizes.end(); pit++){
if(pit->second->id == id){ return -1; }
else if(pit++ == Prizes.end()){
Prizes.insert(make_pair(id, p));
}
}
return 0;
}