lundi 3 février 2020

How to design a class method can only be invoked once

I have stateful class, once a class instance is created, its Bar function/method can only be called once otherwise the internal state will mess up. How to design such thing?

Something can warn/error at compile time would be better.

class  Foo {
  bool Bar(string arg...) { do something...}

  // some class member 
  string s;
  int i;
}

Aucun commentaire:

Enregistrer un commentaire