title: Macro alternative for C++ code generation
body: <p>My settings module has some redundant code:</p>
  <pre><code>#include &lt;QSettings&gt;
  
  class MySettings
  {
  public:
      // param1
      void setParam1(QString param1) { _settings.setValue(&quot;param1&quot;, param1); }
      string param1() { return _settings.value(&quot;param1&quot;).toString(); }
  
      // param2
      void setParam2(int param2) { _settings.setValue(&quot;param2&quot;, param2); }
      int param2() { _settings.value(&quot;param2&quot;).toInt(); }
  
      // param3
      void setParam3(int param3) { _settings.setValue(&quot;param3&quot;, param3); }
      int param3() { _settings.value(&quot;param3&quot;).toInt(); }
  
  private:
      QSettings _settings;
  }
  </code></pre>
  <p>I managed to reduce the amount of code to write by using a macro. Here is an example for the <em>QString</em> parameter type:</p>
  <pre><code>#define INTSETTING(setter, getter) \
      void set##setter(QString getter) { settings.setValue(#getter, getter);} \
      QString getter() {return settings.value(#getter).toString();}
  </code></pre>
  <p>Since I'm using C++, I know that macro usage is bad. I'm looking for a cleaner alternative.</p>
  <p>I gave a Qt example (QString) but it is a more general question.</p>
  <h1>Edit:</h1>
  <p>The macros make the definition of the above class much simpler:</p>
  <pre><code>class MySettings
  {
  public:
      STRINGSETTING(Param1, param1)
      INTSETTING(Param2, param2)
      INTSETTING(Param3, param3)
  
      STRINGSETTING(DefaultTitle, defaultTitle)
      INTSETTING(MaxDocCount, maxDocCount)
  
  private:
      QSettings _settings;
  }
  </code></pre>