jjzjj

c++ - Gotw 67 中的一个例子

http://www.gotw.ca/gotw/067.htm中有一个例子intmain(){doublex=1e8;//floatx=1e8;while(x>0){--x;}}当你把double改成float时,在VS2008中就是一个无限循环。根据Gotw的解释:Whatiffloatcan'texactlyrepresentallintegervaluesfrom0to1e8?Thenthemodifiedprogramwillstartcountingdown,butwilleventuallyreachavalueNwhichcan'tberepresentedandforw

c++ - 为什么要用 make_unique 调用来初始化 unique_ptr?

取自:http://herbsutter.com/2013/05/22/gotw-5-solution-overriding-virtual-functions/为什么要写:autopb=unique_ptr{make_unique()};不仅仅是:autopb=make_unique();我唯一的猜测是,如果我们想要auto,我们需要帮助它推断出正确的类型(这里是base)。如果是这样,那么对我来说这将是一个值得怀疑的优点..键入auto然后在=的右侧键入大量初始化..我错过了什么? 最佳答案 嗯,重点是第一个选项使pb一个uni

c++ - 成员函数与非成员函数?

对于在类上运行的函数应该是成员函数还是非成员函数,您的规则是什么?例如,我有一个使用bool矩阵表示迷宫的类。我正在制作一个名为isConnected的函数,它验证迷宫中的2个点是否在同一区域(即可以从A到B)。这应该是成员(member)还是非成员(member)?什么是好的规则? 最佳答案 HerbSutter说“如果可能的话,我们想让他们成为非成员(member)非friend”,他比我聪明。http://www.gotw.ca/gotw/084.htm 关于c++-成员函数与非成

c++ - GotW #35 中关于 typename 的 Herb Sutter 代码笑话是否已过时?

我正在阅读typename上的一篇旧GuruoftheWeek文章,#35.在最后,您可以找到以下代码段:#includeusingstd::cout;usingstd::endl;structRose{};structA{typedefRoserose;};templatestructB:T{typedeftypenameT::rosefoo;};templatevoidsmell(T){cout::foo());}我不明白这个。我的第一个猜测是第二个smell调用导致模板smell由于一些你很容易忽略的事情而被实例化(这个笑话应该是关于什么的,否则?!)。但是这两个调用都会导致打印

c++ - 最终类的用例

我正在阅读comments在HerbSutter的GuruoftheWeekredux上关于virtual函数,最后看到他提到这个:[...]“usesoffinalarerarer”–well,theysortofare.Idon’tknowofmany,andduringstandardizationBjarnerepeatedlyaskedforexamplesofproblemsitsolvedandpatternswhereitshouldbeused,andIdon’trecallanymajoronesthatstoodout.TheonlyoneIknowofoffha

c++ - 最终类的用例

我正在阅读comments在HerbSutter的GuruoftheWeekredux上关于virtual函数,最后看到他提到这个:[...]“usesoffinalarerarer”–well,theysortofare.Idon’tknowofmany,andduringstandardizationBjarnerepeatedlyaskedforexamplesofproblemsitsolvedandpatternswhereitshouldbeused,andIdon’trecallanymajoronesthatstoodout.TheonlyoneIknowofoffha

c++ - GotW #101 "solution"真的能解决什么问题吗?

首先阅读Herb的SuttersGotW关于C++11中的pimpl的帖子:GotW#100:CompilationFirewalls(Difficulty:6/10)GotW#101:CompilationFirewalls,Part2(Difficulty:8/10)我在理解GotW#101中提出的解决方案时遇到了一些问题。据我所知,在GotW#100中辛苦解决的所有问题都卷土重来:pimpl成员是离线模板,并且定义在使用时不可见(在classwidget的类定义和隐式生成的widget的特殊成员函数中)。也没有任何明确的实例化。这将在链接期间导致Unresolvedexterna

C++ 最令人头疼的解析又来了

这个问题在这里已经有了答案:AconfusingdetailabouttheMostVexingParse(4个回答)关闭3年前。直接取自http://herbsutter.com/2013/05/09/gotw-1-solution/虽然widgetw();对我来说很清楚,但我不知道下面的代码如何成为函数声明?//sameproblem(gadgetanddoodadaretypes)//widgetw(gadget(),doodad());//pitfall:notavariabledeclaration这怎么可能? 最佳答案

C++ 最令人头疼的解析又来了

这个问题在这里已经有了答案:AconfusingdetailabouttheMostVexingParse(4个回答)关闭3年前。直接取自http://herbsutter.com/2013/05/09/gotw-1-solution/虽然widgetw();对我来说很清楚,但我不知道下面的代码如何成为函数声明?//sameproblem(gadgetanddoodadaretypes)//widgetw(gadget(),doodad());//pitfall:notavariabledeclaration这怎么可能? 最佳答案