mardi 26 novembre 2019

How do I put extra-statements in list-initialization?

Given I have a class with a constructor which looks as follows:

MClass(const char *t_source);

In fact there are a lot of places where t_source is obtained from a file, so I'm considering making another constructor which takes FILE pointer instead and put most of the boilerplate inside of it. At the same time existing constructor also has a lot of use by itself and contains logic which i don't want to repeat more than once in the code. I was thinking about delegating constructor but can't see any way how i can leverage this feature as i need more than one statement to extract data from a FILE instance (like allocating a char array and reading from the FILE and deleting afterward). So essentially I want to do something like this:

MClass(FILE *t_file) : MClass(MNameSpace::readFile(t_file)) {}

But with some preliminary and post-call actions. Any idea?

Aucun commentaire:

Enregistrer un commentaire