Fair and simple: How do I check if anything else but an integer is passed to my class in c++?
If I pass f.e. a char 'a' my class gets number 97 in ascii.
I tried std::numeric_limits but I don't get why it is not detecting integers:
#include <iostream> #include <limits> class integerCheck { public: integerCheck(int value) { if((value != std::numeric_limits<int>::is_integer)) return; std::cout << value << std::endl; } }; int main() { integerCheck valInt(88); integerCheck valChar('a'); integerCheck valFloat(13.44f); return 0; } I found this Post working with std::enable_if but I can't imagine there is no way to detect wrong input even in c++20 but wrapping everything in a template.
What am I missing, what should I look/search for to detect anything but an integer value? Thanks upfront
intobject has a value 97, there is no special label or designation of any kind that tells you whether it's really the value 97, or 'a'. C++ simply doesn't work this way. It's 97. That's all you know.numeric_limitsis very confused—it’s checking the argument value (converted from whatever type) against a constanttrue. More study is required.integerCheck(1)andintegerCheck((char)1), right? But those call the same function with the same parameter value, so how would that work?