tags:

views:

60

answers:

2

Relevant portion of the .h file:

template<class T, class W>
T inputValidate( T input, W minVal, W maxVal);

Relevant portion of the .cpp file:

T inputValidate( T input, W minVal, W maxVal)
{
  if (input < minVal || input > maxVal)
  {
    cout << "Invalid input! Try again: ";
    cin input;
  }

return input;
}

I get an error of "error: ‘T’ does not name a type"

+3  A: 

You need to repeat the template declaration before your function definition:

template<class T, class W>
T inputValidate( T input, W minVal, W maxVal)
{
  ...
}
casablanca
now I get: undefined reference to `short inputValidate<short, int>(short, int, int)'
read James's comment to your question
Ben Voigt
Im not sure what James' Link is saying. I don't understand what I should do.
@user450632: If you have a question for someone, you can use `@theirusername` (like `@James`) and they will be notified. To answer your question: You have to define the function template in the header file, not in the .cpp file.
James McNellis
+1  A: 

You must define the function as:

template <class T, class W> T inputValidate(T input, W minVal, W maxVal) {

}
Meher
Im not sure what James' Link is saying. I don't understand what I should do.
@user450632: There are other files where you are including the above header file using #include "validate.h" or something similar. Instead of that, just use #include "validate.cpp".
Meher