开发者

Template function with template return type in C++

开发者 https://www.devze.com 2023-01-19 18:34 出处:网络
Relevant portion of the .h file: template<class T, class W> T inputValidate( T input, W minVal, W maxVal);

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 inputVa开发者_StackOverflow社区lidate( 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"


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

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


You must define the function as:

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

}
0

精彩评论

暂无评论...
验证码 换一张
取 消