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

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Sign Up Now
or Subscribe for future quizzes