Template function don't work as inline function. Why?

I have this:
1
2
3
4
5
6
7
8
9
string input;
unsigned short choice;
...
istringstream valid(input);
...
if(!(valid >> choice))
{
   //some error
}

Ok. My code is almost 1000 lines, and I have splited some functions in headers. But the same function doesn't work:
1
2
3
4
5
template <typename T> bool valid_input(const string& input, T var)
{
    istringstream valid(input);
    return (valid >> var);
}


You can check it here: http://coliru.stacked-crooked.com/a/0f22981e72360f6f
The output is correct, but in my machine with C++11, MinGW 4.8 (64 bit in a 64bit-Windows8), the output is incorrect. Why?

If you want more specific info, the problem is that I use input, I think. I use std::getline(std::cin, some_string).
Last edited on
Is your program fails on same test you posted on Coliru? Because there should not be errors, and it works with 64bit MinGW GCC 8.8.1 compiler on 64bit Win7.
No, it doesn't. By that I think that the error appears because of the input...
ON what input it fails?
Shouldn't it be
template <typename T> bool valid_input(const string& input, T& var) // <-- T&, not T
?
Topic archived. No new replies allowed.