title: C++ class with setter that takes an input pointer to later return value to that pointer
body: <p>I've tried in four different ways to get this to work. I want to assign variables to capture the interface inputs when I call "get_all."</p>
  
  <hr>
  
  <h2>1 - fails because of my lack of understanding of templates</h2>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;map&gt;
  using namespace std;
  #include &lt;boost/lexical_cast.hpp&gt;
  
  class interface {
      template &lt;typename t&gt; struct val_t{ t val; t&amp; out; };
  
      map&lt;string, val_t&gt; KeyDict;
  
      template &lt;typename t&gt; void add(t&amp; out, string key, t value) {
          KeyDict[key] ={ value, out };
      }
  
      template &lt;typename t&gt; void get_all() {
          for (auto i = KeyDict.begin(); i != KeyDict.end(); ++i) {
              i-&gt;second().out = boost::lexical_cast&lt;t&gt;(i.second().val);
          }
      }
  };
  
  int main() {
      int i;
      double d;
      string s;
      bool b;
  
      interface ui;
  
      ui.add(i, "my int", 1); // if it's not possible do to 1 here, I could do "1";
      ui.add(d, "my double", 3.14);
      ui.add(s, "my string", "good stuff");
      ui.add(b, "my bool", false);
  
      ui.get_all();
  
      cout &lt;&lt;
          "int = " &lt;&lt; i &lt;&lt; endl &lt;&lt;
          "double = " &lt;&lt; d &lt;&lt; endl &lt;&lt;
          "string = " &lt;&lt; s &lt;&lt; endl &lt;&lt;
          "bool = " &lt;&lt; b &lt;&lt; endl;
  }
  </code></pre>
  
  <hr>
  
  <h2>2 - For some reason add() doesn't like string</h2>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;map&gt;
  #include &lt;boost/any.hpp&gt;
  
  using namespace std;
  
  class interface {
  public:
  
      struct any { boost::any out; boost::any val; };
      map&lt;string, any&gt; KeyDict;
  
      template &lt;typename t&gt; void add(t&amp; out, string key, t defval) { KeyDict[key].out = defval; KeyDict[key].val = defval; }
  
      void get_all() {
          for (auto i = KeyDict.begin(); i != KeyDict.end(); ++i) 
              i-&gt;second.out = i-&gt;second.val;
      }
  };
  
  int main() {
      int i = 0;
      double d = 0;
      string s = "";
      bool b = 0;
  
      interface ui;
  
      ui.add(i, "my int", 1); // if it's not possible do to 1 here, I could do "1";
      ui.add(d, "my double", 3.14);
      ui.add(s, "my string", "good stuff");
      ui.add(b, "my bool", false);
  
      ui.get_all();
  
      cout &lt;&lt;
          "int = " &lt;&lt; i &lt;&lt; endl &lt;&lt;
          "double = " &lt;&lt; d &lt;&lt; endl &lt;&lt;
          "string = " &lt;&lt; s &lt;&lt; endl &lt;&lt;
          "bool = " &lt;&lt; b &lt;&lt; endl;
  
      cin.get();
  }
  </code></pre>
  
  <hr>
  
  <h2>3 - error: attempting to reference a deleted function</h2>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;map&gt;
  
  using namespace std;
  
  class interface {
  public:
      struct typer {
          int&amp; i_out;
          double&amp; d_out;
          bool&amp; b_out;
          string&amp; s_out;
  
          int i = 0;
          double d = 0;
          bool b = 0;
          string s;
          char t = 0;
      };
  
      map&lt;string, typer&gt; KeyDict_i;
      map&lt;string, typer&gt; KeyDict_d;
      map&lt;string, typer&gt; KeyDict_b;
      map&lt;string, typer&gt; KeyDict_s;
  
      void add(int&amp; out, string key, int val) { KeyDict_i[key].i_out = out; KeyDict_i[key].i = val; KeyDict_i[key].t = 'i'; }
      void add(double&amp; out, string key, double val) { KeyDict_d[key].d_out = out; KeyDict_d[key].d = val; KeyDict_d[key].t = 'd'; }
      void add(bool&amp; out, string key, bool val) { KeyDict_b[key].b_out = out; KeyDict_b[key].b = val; KeyDict_b[key].t = 'b'; }
      void add(string&amp; out, string key, string val) { KeyDict_s[key].s_out = out; KeyDict_s[key].s = val; KeyDict_s[key].t = 's'; }
  
      void get_all() {
          for (auto i = KeyDict_i.begin(); i != KeyDict_i.end(); ++i) i-&gt;second.i_out = i-&gt;second.i;
          for (auto i = KeyDict_d.begin(); i != KeyDict_d.end(); ++i) i-&gt;second.d_out = i-&gt;second.d;
          for (auto i = KeyDict_b.begin(); i != KeyDict_b.end(); ++i) i-&gt;second.b_out = i-&gt;second.b;
          for (auto i = KeyDict_s.begin(); i != KeyDict_s.end(); ++i) i-&gt;second.s_out = i-&gt;second.s;
      }
  };
  
  int main() {
      int i = 0;
      double d = 0;
      string s = "";
      bool b = 0;
  
      interface ui;
  
      ui.add(i, "my int", 1); // if it's not possible do to 1 here, I could do "1";
      ui.add(d, "my double", 3.14);
      ui.add(s, "my string", "good stuff");
      ui.add(b, "my bool", false);
  
      ui.get_all();
  
      cout &lt;&lt;
          "int = " &lt;&lt; i &lt;&lt; endl &lt;&lt;
          "double = " &lt;&lt; d &lt;&lt; endl &lt;&lt;
          "string = " &lt;&lt; s &lt;&lt; endl &lt;&lt;
          "bool = " &lt;&lt; b &lt;&lt; endl;
  }
  </code></pre>
  
  <p>#3 is the most straightforward because I'm not using any boost or templates. Perhaps that would be the easiest to get working from what I already have?</p>