Solution: Manage the Implicit Conversion
The solution to the challenge, 'Exercise: Manage the Implicit Conversion'.
We'll cover the following...
Solution
Press + to interact
#include <iostream>#include <type_traits>#include <typeinfo>struct MyBool {template <typename T>explicit(!std::is_same<T, bool>::value) MyBool(T t) {std::cout << typeid(t).name() << '\n';}};void needBool(MyBool b){}int main() {MyBool myBool1(true);MyBool myBool2 = false;needBool(myBool1);needBool(true);// needBool(5);// needBool("true");}
The ...