title: C++ Check Data Type in Class Function
body: <p>I know there are several answers similar to this question already but I think my lack of experience in C++ is preventing me from understanding them fully.</p>
  <p><strong>Problem</strong>: I have an assignment where I need the user to enter a value which should be of type 'double'. I then need to pass that user input into a custom method for a class I created and have the method validate that this input is indeed a 'double'.</p>
  <p>I saw several posts where people validated the data type right after it was entered using a <code>while</code> loop and the <code>cin</code> operator. This doesn't help me because I need to validate the data type in the method.</p>
  <p>Here is what I have so far:</p>
  <p><strong>Main.cpp:</strong></p>
  <pre><code>...
  int main() {
  
      string name;
      double gpa;   // value that should be validated
  
      cout &lt;&lt; Enter GPA: &quot;;
      cin &gt;&gt; gpa;
  
      myClass student_1;
      student_1.validateGPA(gpa); 
  
      return 0;
  }
  </code></pre>
  <p><strong>myClass.h</strong></p>
  <p>...</p>
  <pre><code>template &lt;class validation&gt;
  void validateGPA(validation);
  </code></pre>
  <p><strong>myClass.cpp</strong></p>
  <p>...</p>
  <pre><code>template &lt;class validation&gt;
  string myClass::validateGPA(validation gpa) {
      return typeid(newGPA).name();
  } 
  </code></pre>
  <p>As written currently I am receiving this Error:</p>
  <pre><code>Severity    Code    Description Project File    Line    Suppression State
  Error   LNK2019 unresolved external symbol &quot;public: class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; __thiscall myClass::validateGPA&lt;double&gt;(double)&quot; (??$validateGPA@N@myClass@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@N@Z) referenced in function _main    GPA_Assignment  C:\Users\josep\source\repos\ccv\GPA\GPA\GPA_Assignment.obj  1   
  </code></pre>
  <p>Without templating the function, the program ran but no matter what I entered at the prompt, the validation method always returned 'double'. I am assuming that is bc of how I declared the gpa varaible in the beginning, but I don't know a better way.</p>
  <p>Thoughts!??</p>