What will the following code print?
#include <iostream>

struct A {
    operator int() {
        return 1;
    };
    
    operator double() {
        return 2.0;
    }
};

int main() {
    A a;
    
    int i = a;
    float x = a;
    x += i;
    
    std::cout << x;
}
Explanation
Conversion "a" to the float type is ambiguous. The "double()" operator, in this case, has no advantages over the "int()".
operator
13.3.3 Best Viable Function

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты