|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-09-14 07:05:53
Scott Meyers <usenet_at_[hidden]> writes:
> Marshall Clow wrote:
>> At 9:06 PM -0700 9/13/06, Scott Meyers wrote:
>> [ snip ]
>>> I'll note that C++ itself allows "uninitialized" objects with
>>> constructors to be created all the time:
>>>
>>> std::ofstream ofs;
>>> std::vector<int>::iterator i;
>>> std::string s;
>>
>> Just a nit - I think that your third example is not like the others.
>> A std::string, AFAIK, constructed with the default constructor, is
>> perfectly valid - just empty.
>
> In each case, a default constructor is invoked. They're all valid
> objects that presumably fulfill their invariants, it's just that you
> can't safely invoke very many operations on them. On the string s, for
> example, invoking size is fine, but invoking operator[] is not fine at all.
The difference is that there are no special cases in the specification
of std::string to cover the default-constructed case. The other two
may fall within the invariants, but they're degenerate objects
requiring special consideration.
-- 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