title: How to passing a data type into a parameter instead of a variable
body: <p>I wrote a simple input validation function to check if the user has entered the right data type and if not it'll keep asking them to re-enter until they do. Now this is something that I use a lot and in most cases I am using it on multiple data types at a time. So instead of duplicating the function and changing the data type of num inside the method is there a way I can simply just pass a data type as the parameter and have it change inside the function too? </p>
  
  <pre><code>float cinInputValidation(){
      float num;
      while(!(cin&gt;&gt; num)){
          cout&lt;&lt; "Error: Invalid Input.\n"
          &lt;&lt; "Please try again: ";
          cin.clear();    //  Clears cin flags if user enters variable of the wrong data type.
          cin.ignore(100, '\n');  //  Ignores up to 100 characters or until a new line.
      }
      return num;
  }
  </code></pre>
  
  <p>Now I am aware of typeof() and I have a hunch I can use it as a parameter like so</p>
  
  <pre><code>cinInputValidation(typeof(float))
  </code></pre>
  
  <p>but what would I do about the functions datatype itself and the type declaration of the num variable? Or is this just not possible.  </p>