Is there a function that would gather all objects of one class?
Is there a function that would gather all objects of one class?
i don't believe so...
you mean for garbage collection? i think the only thing you can do (inside of c++) is to organize your objects better. (maybe a linked list?)
In the Ctor of your class you can store pointers to the generated object in a list:
or something like thatCode:Class::Class(...) { objects.push_back(this); //objects is a list<Class*> ... } Class::~Class() { objects.erase(objects.find(this)); } static const list<Class*>& Class::getAllObjects() const { return objects; }
Hope you don't mind my bad english, I'm Austrian!
I meant to gather as in if personx=anyoftheobjectsx || if persony=anyoftheobjectsy...
Place all classes in an array/linked list, then traverse it checking if any of them equals what you're checking against
Code:#define NrOfEnemies 14 class ENEMY { ... }; class PLAYER { ... }; int main() { PLAYER Player; ENEMY Enemy[NrOfEnemies]; ... for(int i=0; i<NrOfEnemies; i++) { if(Player.GetPosition() == Enemy[i].GetPosition()) { //Do something } } ... return 0; }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.