0

I am parsing command line arguments in my C++ application. This works fine.

Some of these command line arguments are used to generate verbose or debug output in the console. So technically all objects and the whole application must have access to the command line arguments.

I can imagine either passing the command line arguments to all objects or implementing a singleton design pattern.

What other options are there and what would be the best option?

Martin Sand
  • 482
  • 1
  • 8
  • 14
  • Perhaps you could use a global (singleton) object for "settings" or "configuration" which contains all global options and flags. Then query that object from the code that needs it. – Some programmer dude Jul 02 '21 at 07:13
  • I've always shied away from singletons [Singleton: How should it be used](https://stackoverflow.com/q/86582/3422102), but this instance may be one of the valid use cases. – David C. Rankin Jul 02 '21 at 07:40
  • Absolutely @DavidC.Rankin, that is why I am not sure to use it. But passing the arguments to every object is also an overkill depending on the number of classes. I am really unsure here. – Martin Sand Jul 02 '21 at 07:58

0 Answers0