title: C++ make a variable type depend on user input
body: <p>I want a function that creates an array for testing purposes:</p>
  
  <ul>
  <li>The idea es to make the user select the type of elements the array will contain (int, float, double).</li>
  <li>Then it has to return an array of the selected type and <strong>main</strong> has to use it as a parameter. I understand this is done using a <strong>void pointer</strong>, but I would be glad if someone could provide me an example. </li>
  </ul>
  
  <p>So this would be the example code</p>
  
  <pre><code>    **type** vector()
      {
      int t;
      int op;
      cout &lt;&lt; "Size: \n";
      cin &gt;&gt; t;
      **type** * v = new **type**[t]
      cout &lt;&lt; "Select type\n";
      cin &gt;&gt; op;
      switch(op) {
       case 0:
              // Create the array with the selected option...
              return * v;
       case 1:
              // Create the array with the selected option...
              return * v;
       default:
              // Other stuff;
                 }
      }
  </code></pre>
  
  <p>So the question would be what type of function should I use, and also what type of dynamic variable should I declare as v.</p>
  
  <p>And also how to use it later on other functions once correctly done.</p>
  
  <p>Thanks.</p>