incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Travis Vitek" <Travis.Vi...@roguewave.com>
Subject RE: ios_base::Init::Init ();
Date Thu, 08 May 2008 23:27:42 GMT
 

>Martin Sebor wrote:
>
>Travis Vitek wrote:
>>  
>> ios_base::Init::Init() is the constructor for the type 
>> ios_base::Init. You probably shouldn't be calling it
>> directly, I'm almost surprised that it compiles. At the
>> very least you should be using it by creating an
>> object of that type so that the destructor is called.
>> 
>> You should not normally have to do this. It should be done 
>> automatically for you at dynamic initialization time.
>
>Right. On most platforms it should happen when the <iostream>
>header is #included. But calling Init() directly is perfectly
>fine and has the same effect as #including <iostream>.

I've never seen a constructor explicitly invoked like

  Type::Type();

but it does seem to work [obviously]. One issue with this is
that it doesn't just invoke the constructor it actually makes
an unnamed temporary, and that temporary's destructor is invoked
immediately.

If you are using an explicit call to the ios_base::Init::Init()
to initialize the streams for the first time, then it is likely
that the destructor that is called will immediately switch the
streams to unbuffered mode.

So technically it doesn't have the same effect as including
<iostream>. :P

Travis


Mime
View raw message