vendredi 13 mars 2020

Automate Setting IDs according to Number of Instances

I have a simple method in my class, which sets Ids

void Instructor::setInstrID(const int newInstrID)
{
     instrID = newInstrID;
}

I want that instead of manually setting the id, I formulate a way such that the first instance of Instructor gets the id 0 automatically and when the second one is initialized, it should automatically have the Id = 1 and so on. Now I am not sure how to do this.

Should this be within the method? Or should it be in my main() function? How could I check if there are any existing instances? I thought of making a vector but then that would be in main() and I didn't really wanna do that. Any leads?

Aucun commentaire:

Enregistrer un commentaire