Writing a function using a macro with variable number of arguments
<p>How do you write a macro with variable number of arguments to define a function? Suppose that we define the class <code>class1</code> with 2 parameters and class <code>class2</code> with three parameters. </p>

<pre><code>class class1 {
public:
   int arg1;
   int arg2;
   class1(int x1, int x2): arg1(x1), arg2(x2) {}
};
class class2 {
public:
   int arg1;
   int arg2;
   int arg3;
   class1(int x1, int x2, int x3): arg1(x1), arg2(x2), arg3(x3) {}
};
</code></pre>

<p>For each class that I define or even classes that have been defined before I want to write the following:</p>

<pre><code>template&lt;&gt; inline void writeInfo&lt;class1&gt;(const class1&amp; obj, FILE* fp) {
    writeAmount(2, fp);
    writeName("arg1", fp);
    writeInfo(obj.arg1, fp);
    writeName("arg2", fp);
    writeInfo(obj.arg2, fp);
}
template&lt;&gt; inline void writeInfo&lt;class2&gt;(const class2&amp; obj, FILE* fp) {
    writeAmount(3, fp);
    writeName("arg1", fp);
    writeInfo(obj.arg1, fp);
    writeName("arg2", fp);
    writeInfo(obj.arg2, fp);
    writeName("arg3", fp);
    writeInfo(obj.arg3, fp);
}
</code></pre>

<p>We do not need to care about the definitions of <code>writeAmount</code>, <code>writeName</code> or <code>writeInfo</code>. What I would like to do is write something like:</p>

<pre><code>MACROWRITEINFO(class1, 2, arg1, arg2);
MACROWRITEINFO(class2, 3, arg1, arg2, arg3);
</code></pre>

<p>Is it possible to create such macro so that it can expand to the above template definitions? I've read in a lot of places that macros are evil, but in this case I believe that they are very helpful since they'll reduce the amount of code I type and thus the amount of typos I'll make during the creation of the template functions.</p>
