Consider this simple example code:
#include
#include
void f(bool _switch) {
std::cout << \"Nothing really\" &l
You can get rid of the implicit conversion by creating a helper class
#include
#include
struct Boolean {
bool state;
Boolean(bool b):state(b){}
operator bool(){ return state; }
};
void f(Boolean _switch) {
std::cout << "Nothing really " << _switch << std::endl;
}
void f(std::function _f) {
std::cout << "Nothing really, too" << std::endl;
}
int main ( int argc, char* argv[] ) {
f([](int _idx){ return 7.9;});
f(true);
return 0;
}
Should you ever want to call f
with eg. a pointer and expect it to call the first overload you will have to cast it to either bool
or add a corresponding constructor / cast to the helper class though.