title: C++ Macro define and undefine
body: <p>I want to use macros to quickly create inlined functions in headers, these functions are related to a base class wich I am subclassing. I'll put the definitions inside the base calss header but I do not want to pollute everything that include these headers with all macro definitions, so I would like to write something like this (which unfortunately doesn't work):</p>
  
  <pre><code>#define BEGIN_MACROS \
  #define MACRO_1(...) ...\
  #define MACRO_2(...) ...\
  #define MACRO_3(...) ...
  
  #define END_MACROS \
  #undef MACRO_1\
  #undef MACRO_2\
  #undef MACRO_3
  </code></pre>
  
  <p>And then use it like:</p>
  
  <pre><code>BEGIN_MACROS
      MACRO_1(...)
      MACRO_2(...)
      MACRO_3(...)
  END_MACROS
  </code></pre>
  
  <p>perhaps should I use something like this?</p>
  
  <pre><code>#include "definemacros.h"
      MACRO_1(...)
      MACRO_2(...)
      MACRO_3(...)
  #include "undefmacros.h"
  </code></pre>
  
  <p>And put definitions and "undefinitions" in two separate headers...</p>
  
  <p>Or is there a bettter approach overrall to overcome this kind of problems?
  Or do you suggest to avoid at all the use of macros and/or macros in headers?</p>
  
  <p>Edited to include specific use case:</p>
  
  <p>definition:</p>
  
  <pre><code>#define GET_SET_FIELD_VALUE_INT(camelcased, underscored)\
  inline int rget ## camelcased () { return this-&gt;getFieldValue( #underscored ).toInt(); }\
  inline void rset ## camelcased (int value) { this-&gt;setFieldValue( #underscored , value); }
  </code></pre>
  
  <p>use:</p>
  
  <pre><code>class PaymentRecord : public RecObj
  {
  public:
      GET_SET_FIELD_VALUE_INT(PriceIndex, price_index)
  //produces this
      inline int rgetPriceIndex() { return this-&gt;getFieldValue("price_index").toInt(); }
      inline void rsetPriceIndex(int value) { this-&gt;setFieldValue("price_index", value); }
  
  };
  </code></pre>