title: C++: Create a getter using a struct of constant references
body: <p>Assuming I have the following class</p>
  <pre class="lang-cpp prettyprint-override"><code>class Foo {
  public:
      // ...
  private:
      std::unordered_map&lt;std::string, int&gt; param1;
      std::vector&lt;int&gt; param2;
      // And other complex data types
  };    
  </code></pre>
  <p>and want to access the private members of its instance from external function, can I define a structure of constant references to pass them all at once, instead of creating a getter for each one and passing a &quot;zoo&quot; of parameters?</p>
  <pre class="lang-cpp prettyprint-override"><code>struct params_t {
      const std::unordered_map&lt;std::string, int&gt; &amp;param1;
      const std::vector&lt;int&gt; &amp;param2;
  };
  
  params_t Foo::get_params() { return params_t{param1, param2}; }
  
  void bar()
  {
      // Initialize an instance of Foo
      params_t params = foo.get_params();
      // Do something with params
  }
  </code></pre>
  <p>Is it considered a good practice? Because in my case, my needs are specific: I need all parameters at once and I need them often, so I aim for efficiency and low memory usage rather than code style.</p>