what is the best way of sharing a configuration object across classes?
<p>Let us say that I have the classes M, A, B, C. M is the main class of my application (that is the one that does most of the job) and has this structure</p>

<pre><code>class M {
  public:
    // Something here.
  private:
    Conifg config;
    A a;
    std::vector&lt;B&gt; bs;
    const C* c;
};
</code></pre>

<p>In a main I create an instance m of class M and I want to set my config object, say by reading it from a file. The configuration object is nothing special, it could be a protocol buffer or a simple struct.</p>

<p>Now, I want a, b and c to be able to access the config object, because there are some global settings that they need. These settings are global, they do not change, and are the same for each instance of A, B and C (and M). What I am currently doing, is having a static field in each class A, B and C and I am setting a copy of the configuration object for each instance of these classes. I do not want these classes to know of the existence of M. Is this the best solution? Should I perhaps think of a global config variable?</p>
