I have a relatively long (10k lines) C++ code in which I use three global singletons.
ClassA Singleton_A;
ClassB Singleton_B;
ClassC Singleton_C;
int main(int argc, char* argv[])
{
// DoStuff with argc and argv
}
I would now like to modify the code to loop through DoStuff
more than once which would be given as first argument of argv
. I am unsure how to deal with my global singletons.
One way to go would be to encompass the whole current code in a class with something like
class Process
{
ClassA Singleton_A;
ClassB Singleton_B;
ClassC Singleton_C;
int main(int argc, char* argv[])
{
// DoStuff with argc and argv
}
};
int main(int argc, char* argv[])
{
Process process;
int NbRepeats = std::stoi(std::string(argv[0]));
for (int repeat ; repeat < NbRepeats; repeat++)
{
process.main(argc--, argv++);
}
}
Does it seem like a good design?
Aucun commentaire:
Enregistrer un commentaire