22
I'm puzzled with this behavior of C++:
struct A {
virtual void print() const { printf("a\n"); }
};
struct B : public A {
virtual void print() const { printf("b\n"); }
};
struct C {
operator B() { return B(); }
};
void print(const A& a) {
a.print();
}
int main() {
C c;
print(c);
}
So, the quiz is, what is the output of the program - a or b? Well, the answer is a. But why?