title: C/C++ Macro: How to generate two separate sections of code with one macro (boost preprocessor library?)
body: <p>I'm looking for a method or a way to generate a list of typedefs and a list of object instantiations from a list of macro-invocations, defining the class types and the constructor parameters of these objects.</p>
  
  <p>It should look like the (not working) code below. The problem to solve is a way to generate two different lists out of one list of macro invocations. I guess this is a problem to solve with the boost preprocessor library part but I have now glue how to do.</p>
  
  <pre><code>/////////////////////////////////////////////////////////////////////////////////
  // MACRO-Definitions
  #define DEF_OBJECT_TYPE(name, class, contructor_params) \
    typedef class name ## type;
    name ## type* name;
  
  #define DEF_OBJECT_RUN(name, class, contructor_params) \
    name ## type* name = new name ## type contructor_params; \
  
  #define DEF_OBJECTS(definitions) \
    /* Type-Header */ \
    definitions \
    /* Type-Footer */ \
    /* Run-Header */ \
    definitions \
    /* Run-Footer */
  
  #define OBJECT(name) (dynamic_cast&lt;name ## type*&gt;(name))
  
  /////////////////////////////////////////////////////////////////////////////////
  // Object-Definitions
  DEF_OBJECTS(
    DEF_OBJECT(Object1, CClass1, ("par1"))
    DEF_OBJECT(Object2, CClass2, ("par1", "par1"))
  )
  
  /////////////////////////////////////////////////////////////////////////////////
  // This shall be the result of the macro expansion
  // shall expand to:
  struct MyClass {
  
    typedef class Object1type;
    Object1type* Object1;
  
    typedef class Object2type;
    Object2type* Object2;
  
    void Run();
  }
  
  void MyClass::Init() {
    Object1type* Object1 = new Object1type("par1");
    Object2type* Object2 = new Object2type("par1", "par2");
  }
  // end of expansion
  /////////////////////////////////////////////////////////////////////////////////
  
  // I want to use these automatic created objects in this way:
  void MyClass::Run() {
    OBJECT(Object1)-&gt;method_class1(1);
    OBJECT(Object2)-&gt;method_class2(1,2);
  }
  </code></pre>