template <class T>
T Read () {
T t;
cin >> t;
if (cin.fail()) {
// ...
}
return t;
}
This generic code read value of type T with some additional error handling. It relies on having operator>> that can parse T, and in this way it is extensible to new types.
What I didn't realize is that it relies on T having a default constructor. Now I've hit into this problem.
What are my options?
What is the right way to do it?