When I write bool x = "hallo"
, there is no error. It is assumed that the non-zero value is implicitly converted into a Boolean value, which represents the number 1:
#include <iostream>
using namespace std;
int main() {
bool x = "hallo;
cout << x << "\n";
return 0;
}
But in other cases, there is an error, eg:
#include <iostream>
using namespace std;
int main() {
string text = "hallo";
bool x = text;
cout << x << "\n";
return 0;
}
Why is this different?
An error should not occur, because it is assumed that the text value is considered a non-zero value, so output should be 1.