title: How to create a global parameters object
body: <p>Here's a common, simple task: Read configuration settings from a configuration file, save the settings (e.g. as a hash) in an object, access this object from various objects that need to access the configuration parameters.</p>
  
  <p>I found <a href="http://www-personal.umich.edu/~wagnerr/ConfigFile.html" rel="noreferrer">this implementation</a> for the ConfigFile class implementation and it works. My question is: what is the best way to make an instance of this class available from my other classes and be thread safe, avoid static initialization order fiasco, etc.</p>
  
  <p>My current approach is to construct it in main() using</p>
  
  <pre><code>    // Read face detection related parameter values from the configuration file.
  string configFileName = "detection_parameters.txt";
  try {
      parameters = ConfigFile( configFileName );
  }
  catch(ConfigFile::file_not_found) {
      cerr &lt;&lt; "configuration file not found: " &lt;&lt; configFileName &lt;&lt; endl;
      exit(-1);
  }
  </code></pre>
  
  <p>and then make <strong>parameters</strong> a global variable. But I also read that singletons should be used instead of global variables. How can the singleton be instantiated with the file name?</p>
  
  <p>This must be such a common task that I think there must be a generally accepted good way of doing it? I would appreciate if someone can point me to it.</p>
  
  <p>Thanks,
  C</p>