开发者

Template function with template return type in C++

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜