Quote:
Originally Posted by
CornedBee
You should remove the throw(...). Throw specifications have patchy support and often do more harm than good.
Okay... I thought I'd add them to allow disambiguation between functions that throws and which does not.
Quote:
The thing won't work with std::wstring, since it will try to write it to cout, not wcout. Frankly, I'd just overload ask() for const std::string& and const std::wstring& and not make it a template at all. const char* and const wchar_t* will be automatically converted to their respective string class forms. This is no efficiency problem, since the next thing you do is wait for user input anyway.
Not to mention, you have a problem with reading in the answer from the narrow stream no matter where you wrote the question to. Not particularly good there.
Perhaps you should just make the whole class a template on the character type and go for the generic versions of everything. You'll need a small trick for switching between cin and wcin and cout and wcout, but that's easy.
I think I get your point. I should disambiguate char and wchar_t and keep it the same all the way for output and input.
That's not a big deal. It should be easy.
Quote:
Templating the class on the result type, on the other hand, seems like it's not a very good idea. This means you may have to create multiple objects for a series of inputs of different types. This may be fine - but it's something to keep in mind. If you do it this way, you should make the object really represent a single input element and thus move the query-error loop inside the object.
That was the original idea - to make the object "an" input, but I don't really know if there's more to be done to enforce that. Eventually, the programmer would want the stored value and the easier way to provide that is the get function.
Otherwise if it can be reused, I suppose I could just make get a template function?
Which approach is best in your mind?
Quote:
Your input guard lacks uniqueness. INPUT_H is far too common a symbol to use as an input guard. There's few things worse than an input guard conflict in two libraries.
Appending a date, such as, INPUT_20081018_H should then work better, I suppose.
Quote:
And finally, the Throw template parameter seems to be a relic. You don't use it anywhere.
Oh yes, I forgot to remove it.
I toyed with the idea to make the class throwable or not by the use of a template parameter, but then decided on overloading functions, like std::vector does.