Здравствуйте, SergeCpp, Вы писали:
SC>Здравствуйте, Centaur!
SC>А как насчёт случая, когда для предотвращения копирования SC>конструктор копирования — запрещён SC>(объявлением его как private и отсутствием определения) ?
Обходиться явным введением области видимости. Или писать предложение в Комитет.
// …some code…
{
Class object(many, constructor, parameters);
if (object)
{
do_the(right.thing);
}
} // here it dies
// …more code…
Переписка с Bjarne Stroustrup
-----------------------------
Смирнов Сергей wrote:
>Good day, Dr. Stroustrup! > >----- Original Message ----- >From: "Bjarne Stroustrup" <bs@cs.tamu.edu> >To: "Смирнов Сергей" <serge@gus.elcom.ru> >Sent: Wednesday, August 10, 2005 9:20 PM >Subject: Re: Simple question — Constructing in condition > > >Смирнов Сергей wrote: > > > >>Good day, Dr. Stroustrup! >> >>It is "ok" to use code like following ? >> >>if( int ok( GetStatus() ) ) // "int" used as example only (i use object of >>some class with "operator bool()" there) >> >> >> >> >You need to use the = initialization syntax: > >if (int ok = GetStatus()) > >========================================== >What if = initialization constructor >(to prevent from copy semantics - >i read in standard that in case of "=" temporary >could — though it may be optimized away — be created) >made private and without definition ? > >Will be "if( SomeClass ok( GetStatus() ) )" valid anyway ? > >
No. I don't recall the reason for requiring the = syntax, but the
requirement is there. Yes, it means that there are a few things you
can't do, but I have not found that a serious problem.
>// SomeClass::operator bool() is properly defined there >========================================== > >Sincerely yours, Sergey Smirnoff > >serge@gus.elcom.ru > >P.S. THANK YOU FOR THE BEST LANGUAGE > >P.P.S. Can you allow me to place your answers >together with my questions to "Constructing in condition" topic >on Russian Software Developer Network Forum ? > >Forum URL — http://rsdn.ru/Forum > > > >
sure.
Здравствуйте, SergeCpp, Вы писали:
SC>Здравствуйте!
SC>Переписка с Bjarne Stroustrup SC>-----------------------------
SC>Смирнов Сергей wrote:
>>Good day, Dr. Stroustrup!