Boost logo

Boost Users :

From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2006-09-14 22:14:21


"Scott Meyers" <usenet_at_[hidden]> wrote in message
news:eeakjb$ho0$1_at_sea.gmane.org...

> I'll note that C++ itself allows "uninitialized" objects with
> constructors to be created all the time:
>
> std::ofstream ofs;

It's funny how this example is the one always chosen by the proponents of 2
phase construction. Search the newsgroups and you'll find this constructor
is the root of many problems encountered by users of streams attempting to
operate on an insufficiently intialized stream object.

> std::vector<int>::iterator i;

I know, I hate this one too. ;)

> std::string s;

This is a properly initialized empty string, analogous to an empty vector.

> In each case, there are a few operations that can legitimately be
> performed on such objects, but many operations lead to UB. Is this
> fundamentally different from the EventLog example? For example, replace
> EventLog in my example with ofstream, and you have
>
> std::ofstream ofs;
> ofs << "Hello World";

What better argument could there be against 2 phase construction?

Jeff Flinn


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