I have a function which accepts an bool as an argument:
void func(bool a)
{
doing something;
}
But when I'm calling the function and passed string to it:
func("false");
Actually it should accept only.
func(false);
It accepts string without any error.
why?
Literal string is a char pointer, and pointer will be implicitly converted to bool.
falsetrueIn this case, the func will receive a true value from the non-null "false" string , which is const char* type.
You may need an interpreter function to able to read "false", "0", "no", etc from keyboard typing and convert to bool false which the program can understand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With