Problematic declaration syntax
Posted 20/08/2009
on:- In: questions
- 2 Comments
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"
Eh, the most vaxine parse 😀
1 | rmn
07/09/2009 at 22:05
A few good replies to this question can now be found on stackoverflow:
http://stackoverflow.com/questions/1379932/trick-question-regarding-declaration-syntax-in-c