jeudi 16 janvier 2020

Calling initialization boiler plate code at start of each function in C++

I've situation which I think is pretty common, but I don't know if there is nice solution for it or not, hence this question.

Class SomeClass {
public:
  void someFunc1() {
      initialize_logging();
      // some specific stuff
  }
  ...
  void someOtherFunc() {
      initialize_logging();
      // some specific stuff
  }
private:
  void initialize_logging() {
     // do some common stuff
  }
};

The code I am working on has several methods and some of them forget to call initialize_logging(). Is there a way to ensure that all the methods by default call it before they do specific stuff?

Aucun commentaire:

Enregistrer un commentaire