mardi 31 mai 2016

C++ global variable that can be changed only in one method, possible?

I'm looking for a way to have an int variable that persists value across method calls. From this perspective a class member will be good.

But I would like that int variable to be changed in only one particular method.

How do I make that?

I tough about

void MyClass::my_method(){
    static int var = 0;
    var++;
}

But, I would like var = 0; to be executed only the first time.

Aucun commentaire:

Enregistrer un commentaire