How to traverse all the members inside a class?
<p><br>
suppose I have a class</p>

<pre><code>class CAT  
{  
private:  
  int a;  
  long b;  
  double c;    
  string d;  
};    
</code></pre>

<p>now I need a function which can initialize all the members to a specific value, for example:</p>

<ul>
<li>int set to 0 </li>
<li>long set to -1    </li>
<li>double set to -1.1    </li>
<li>string set to unknown     </li>
</ul>

<p>so far, I can write  a function named initMembers:</p>

<pre><code>void initMembers()   
{   
    a = 0;   
    b = -1;   
    c = -1.1;   
    d = "unknown";   
}   
</code></pre>

<p>but if I have 1000 classes like CAT, and some of them have 4 members, some of them have 40 members,..... so I have to write an initMember functuions for every class.</p>

<p>I wonder if there is way can traversed all the members inside a class?</p>

<p>Thanks advance for your help!</p>

<p>I mean I want initialize  specific type with a corresponding value </p>

<h2>for all members inside all classes</h2>

<pre><code>* int set to 0
* long set to -1
* double set to -1.1
* string set to unknown
</code></pre>
