I don't want my code to compile or handle invalid input / argument. In this case, it should only accept int variables and nothing else.
#include <iostream>
class calc{
public:
int add2(int x){
return x + 2;
}
};
// Inside testing file
int main(){
calc c;
// Should not output anything / throw error since argument is 'a' and not a integer
std::cout<<c.add2('a'); // But it outputs 99.
}
I understand c++ is doing its implicit conversion here but I don't know how to stop it from happening. Or is there a way to check if the input passed is of int type and nothing else?