Problematic declaration syntax

Posted on: 20/08/2009

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 decleration 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 Responses to "Problematic declaration syntax"

A few good replies to this question can now be found on stackoverflow:

Eh, the most vaxine parse 😀

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 27 other followers


%d bloggers like this: