Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-09-18 10:20:50


"Matthias Hofmann" <hofmann_at_[hidden]> writes:

> "David Abrahams" <dave_at_[hidden]> schrieb im Newsbeitrag
> news:87bqphhxjl.fsf_at_pereiro.luannocracy.com...
>> David Walthall <walthall_at_[hidden]> writes:
>>
>>> The only time I have found it useful to have default-constructed objects
>>> that are otherwise unusable is when I need to store them in a map or
>>> other container that requires a default constructible object.
>>
>> No standard containers have that requirement, though.
>
> This seems to be another defect, as the standard also defines the following
> constructor:
>
> explicit vector(size_type n, const T& value = T(),
> const Allocator& = Allocator());
>
> Now how is the following code supposed to compile:
>
> #include <vector>
>
> struct X
> {
> X( int ) {}
> };
>
> void f()
> {
> // Error: No default constructor for X.
> std::vector<X> v( 5 );
> }

That's not a defect; it's simply _not_ supposed to compile!

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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net