class A
{
public:
operator int() const { return 123; }
operator bool() const = delete;
};
Пробуем 'if', работает как и ожидается:
A a;
if ( a ) {}
main.cpp:27:9: error: use of deleted function ‘A::operator bool() const’
main.cpp:8:2: error: declared here
Пробуем 'switch', не работает:
A a;
switch ( a ) {}
main.cpp: In function ‘int main()’:
main.cpp:23:13: error: ambiguous default type conversion from ‘A’
main.cpp:23:13: error: candidate conversions include ‘A::operator int() const’ and ‘A::operator bool() const’
Почему в случае 'switch' он пытается использовать приведение к bool, которое было удалено? Как правильно запретить неявное приведение к bool?