Handling different datatypes in a single structure
<p>I need to send some information on a VxWorks message queue. The information to be sent is decided at runtime and may be of different data types. I am using a structure for this - </p>

<pre><code>struct structData
{
  char m_chType;    // variable to indicate the data type - long, float or string
  long m_lData;  // variable to hold long value
  float m_fData;    // variable to hold float value
  string m_strData; // variable to hold string value
};
</code></pre>

<p>I am currently sending an array of structData over the message queue. </p>

<pre><code>structData arrStruct[MAX_SIZE];
</code></pre>

<p>The problem here is that only one variable in the structure is useful at a time, the other two are useless. The message queue is therefore unneccessarily overloaded. 
I can't use unions because the datatype and the value are required.
I tried using templates, but it doesn't solve the problem.I can only send an array of structures of one datatype at a time.</p>

<pre><code>template &lt;typename T&gt;
struct structData
{
  char m_chType;
  T m_Data;
}

structData&lt;int&gt; arrStruct[MAX_SIZE];
</code></pre>

<p>Is there a standard way to hold such information?</p>
