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;
Conversion "a" to the float type is ambiguous. The "double()" operator, in this case, has no advantages over the "int()".
13.3.3 Best Viable Function

Следи за CodeGalaxy

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

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