[C++-sig] Newcomer - constructors not working as I'd expect

David Abrahams dave at boost-consulting.com
Mon Apr 10 17:51:24 CEST 2006


Andrew Pontzen <app26 at ast.cam.ac.uk> writes:

>> This doesn't match. I'd try: init<const test1&>()
>
> You're quite right - this fixes it. In retrospect, it is quite obvious 
> that what I was attempting to do would cause undefined behaviour!
> (Although I'm suprised it didn't give me a compile-time error?)

Why should it, and how could it?

A ctor taking a const reference to a temporary is perfectly
legitimate, as long as the ctor doesn't attempt to store it.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




More information about the Cplusplus-sig mailing list