Problematic declaration syntax

This question was written by a friend who luckily let me use it. It presents a very common pitfall of C++, regarding the syntax of declaration statements.

In the following code, what would be the type of b?

struct A {
    A (int i) {}

struct B {
    B (A a) {}

int main () {
    int i = 1;
    B b(A(i));
    return 0;

Hint: you will be surprised! Try printing inside B’s constructor.

2 thoughts on “Problematic declaration syntax

Leave a Reply